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

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

2、安装iText7包

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

4、代码如下:

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

/// <summary>
/// 导出JBIG2
/// </summary>
/// <param name="dictionary"></param>
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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值