static public void ProcessImage(Element image) { bool image_mask = image.IsImageMask(); bool interpolate = image.IsImageInterpolate(); int width = image.GetImageWidth(); int height = image.GetImageHeight(); int out_data_sz = width * height * 3; Console.WriteLine("Image: width=\"{0:d}\" height=\"{1:d}\"", width, height); // Matrix2D mtx = image.GetCTM(); // image matrix (page positioning info) // ++image_counter; // System.Drawing.Bitmap bmp = image.GetBitmap(); // bmp.Save(output_path + "reader_img_extract_" + image_counter.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png); // // Alternatively you can use GetImageData to read the raw (decoded) image data // image.GetBitsPerComponent(); // image.GetImageData(); // get raw image data // another approach is to use Image2RGB filter that converts every image to // RGB format. This could save you time since you don't need to deal with color // conversions, image up-sampling, decoding etc. // ---------------- Image2RGB img_conv = new Image2RGB(image); // Extract and convert image to RGB 8-bpc format FilterReader reader = new FilterReader(img_conv); // byte[] image_data_out = new byte[out_data_sz]; // A buffer used to keep image data. reader.Read(image_data_out); // image_data_out contains RGB image data. // ---------------- // Note that you don't need to read a whole image at a time. Alternatively // you can read a chuck at a time by repeatedly calling reader.Read(buf, buf_sz) // until the function returns 0. }
protected T ReadFilter <T>(byte[] source) where T : BaseFilter { var mem = new MemoryStream(); mem.Write(source, 0, source.Length); mem.Seek(0, SeekOrigin.Begin); var reader = new SwfStreamReader(mem); var filterReader = new FilterReader(); var filter = filterReader.Read(reader); Assert.AreEqual(mem.Length, mem.Position, "Should reach end of stream"); return((T)filter); }
static byte[] FlipImage(Element element) { Image2RGB image2rgb = new Image2RGB(element); int width = element.GetImageWidth(); int height = element.GetImageHeight(); int out_data_sz = width * height * 3; int stride = width * 3; FilterReader reader = new FilterReader(image2rgb); byte[] image_data = new byte[out_data_sz]; byte[] flipped_data = new byte[out_data_sz]; reader.Read(image_data); for (int row = 0; row < height; ++row) { Buffer.BlockCopy(image_data, row * stride, flipped_data, out_data_sz - (stride * (row + 1)), stride); } return(flipped_data); }