PDFから画像を抽出したい。私は今iTextSharpを使用しています。 一部の画像は正しく抽出できますが、ほとんどの画像は正しい色を持たず歪んでいます。 これは、画像の種類を分離コードで、私は別のPixelFormatsといくつかの実験をしましたが、私は私の問題の解決策を取得できませんでした...iTextSharpを使用してExctract FlateDecode画像
:
if (filter == "/FlateDecode")
{
// ...
int w = int.Parse(width);
int h = int.Parse(height);
int bpp = tg.GetAsNumber(PdfName.BITSPERCOMPONENT).IntValue;
byte[] rawBytes = PdfReader.GetStreamBytesRaw((PRStream)tg);
byte[] decodedBytes = PdfReader.FlateDecode(rawBytes);
byte[] streamBytes = PdfReader.DecodePredictor(decodedBytes, tg.GetAsDict(PdfName.DECODEPARMS));
PixelFormat[] pixFormats = new PixelFormat[23] {
PixelFormat.Format24bppRgb,
// ... all Pixel Formats
};
for (int i = 0; i < pixFormats.Length; i++)
{
Program.ToPixelFormat(w, h, pixFormats[i], streamBytes, bpp, images));
}
}
これは、コードにありますImageをMemoryStreamに保存します。イメージをフォルダに保存することは後で実装されます。
private static void ToPixelFormat(int width, int height, PixelFormat pixelformat, byte[] bytes, int bpp, IList<Image> images)
{
Bitmap bmp = new Bitmap(width, height, pixelformat);
BitmapData bmd = bmp.LockBits(new Rectangle(0, 0, width, height),
ImageLockMode.WriteOnly, pixelformat);
Marshal.Copy(bytes, 0, bmd.Scan0, bytes.Length);
bmp.UnlockBits(bmd);
using (var ms = new MemoryStream())
{
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
bytes = ms.GetBuffer();
}
images.Add(bmp);
}
私を助けてください。
5.1.3以降の新機能を使用してこのレスポンスをチェックしてください。http://stackoverflow.com/a/8511314/231316 –
解決策がうまくいくかもしれません(最初の例)。しかし、色はまだ逆でも歪んでいます。お返事をありがとうございます。 –