栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

C#使用iText7以及JBig2Decoder.NET导出JBIG2Decode格式的图片

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C#使用iText7以及JBig2Decoder.NET导出JBIG2Decode格式的图片

1、参考https://blog.csdn.net/XinShun/article/details/103902015

2、安装iText7包

3、JBig2Decoder.NET,注意项目需要为.net4.5版本

4、代码如下:

/// 
/// JBIG2头
/// 
private byte[] Header = new byte[] { 0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x01 };

/// 
/// 导出JBIG2
/// 
/// 
public byte[] ExportJBIG2FromPDF(PdfDictionary dictionary)
{
	PdfDictionary pdfStream = dictionary;
	byte[] b;
	try
	{
		// Get decoded stream bytes.
		b = ((PdfStream)pdfStream).GetBytes();
	}
	catch (PdfException)
	{
		// Get originally encoded stream bytes
		b = ((PdfStream)pdfStream).GetBytes(false);
	}

	//参考PDFReference_1-5.pdf
	//由于JBIG2文件头在PDF中没有使用,
	//这个头没有放在JBIG2流对象中,
	//并被丢弃
	//Since the JBIG2 file header is not used in PDF,
	//this header is not placed in the JBIG2 stream object, 
	//and is discarded
	var jbig2 =  Header.Concat(b).ToArray();

	// 解码
	JBIG2StreamDecoder dec = new JBIG2StreamDecoder();
	// JPEG格式数据
	var jpegData = dec.decodeJBIG2(jbig2, ImageFormat.JPEG);

	//  存为文件
	//using (var fs = new FileStream(@"F:test.jpg", FileMode.Create))
	//{
	//    fs.Write(data, 0, data.Length);
	//    fs.Flush();
	//    fs.Close();
	//}

	return jpegData;
}

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/955656.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号