问题描述
string imgfile = @"C:\users\me\desktop\test.jpg";
Bitmap bmp = new Bitmap(imgfile);
Bitmap bw = ConvertTo1Bpp(bmp); //make b+w
Document doc =
new Document(new iTextSharp.text.Rectangle(bmp.Width, bmp.Height));
PdfWriter.GetInstance(doc,
new System.IO.FileStream(
@"C:\users\me\desktop\test.pdf",
System.IO.FileMode.Create,
System.IO.FileAccess.ReadWrite));
iTextSharp.text.ImgJBIG2 i =
((iTextSharp.text.ImgJBIG2)iTextSharp.text.ImgJBIG2.GetInstance(
bmp, System.Drawing.Imaging.ImageFormat.Bmp));
doc.Open();
doc.Add(i);
doc.Close();
我不能找到这个与iTextSharp的任何好的文档。我所要做的是采取的JPEG文件,并将其转换为嵌入黑白JBIG2图像的PDF文件。我得到的错误是iTextSharp.text.ImageRaw和iTextSharp.text.ImageJBig2之间的一个InvalidCastException ...有什么,我上面有别的选择吗?
I cant find any good documentation for this with iTextSharp. What I am trying to do is take a Jpeg file and convert it into a pdf embedded as a black and white JBig2 image. The error I get is an InvalidCastException between "iTextSharp.text.ImageRaw" and "iTextSharp.text.ImageJBig2"... is there an alternative to what I have above?
修改结果
ImgJBig2刚刚重新$ P $已经psents图像连接$ C $光盘JBIG2我现在相信了。我所寻找的是什么,将采取位图和连接code它变成一个BW JBIG2位图,我可以放入一个PDF文件。
EDIT
ImgJBig2 just represents an image already encoded in JBig2 I believe now. What I am looking for is something that will take a Bitmap and encode it into a BW JBig2 Bitmap that I can put into a Pdf.
推荐答案
据我可以告诉有没有很多选择编码JBIG2并没有原生免费的。
As far as I can tell there's not a lot of options for encoding JBig2 and no native free ones.
- Windows Imaging SDK ($2500+)
- JBIG2 Compression Codec SDK for .NET ($1,800)
- jbig2enc (free but c code only)
最后创建您也许能的P / Invoke进入或在最坏的情况对剧本,所以我认为这是你最好的选择,如果你不想付出CLI程序。比其他格式的JBIG2是否提供这种更大的COM pression?
The last creates a CLI program that you might be able to P/Invoke into or at worst script against so I think that's your best option if you don't want to pay. Does JBIG2 offer such greater compression over other formats?
这篇关于iTextSharp的JBIG2 EN codeR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!