/// <summary> /// Constructs a new FonetImage using the supplied bitmap. /// </summary> /// <remarks> /// Does not hold a reference to the passed bitmap. Instead the /// image data is extracted from <b>bitmap</b> on construction. /// </remarks> /// <param name="href">The location of <i>bitmap</i></param> /// <param name="imageData">The image data</param> public FonetImage(string href, byte[] imageData) { this.m_href = href; m_colorSpace = new ColorSpace(ColorSpace.DeviceRgb); m_bitsPerPixel = DEFAULT_BITPLANES; // 8 // Bitmap does not seem to be thread-safe. The only situation // Where this causes a problem is when the evaluation image is // used. Each thread is given the same instance of Bitmap from // the resource manager. Bitmap bitmap = new Bitmap(new MemoryStream(imageData)); this.width = bitmap.Width; this.height = bitmap.Height; this.m_bitmaps = imageData; ExtractImage(bitmap); }
/// <summary> /// Extracts the raw data from the image into a byte array suitable /// for including in the PDF document. The image is always extracted /// as a 24-bit RGB image, regardless of it's original colour space /// and colour depth. /// </summary> /// <param name="bitmap">The <see cref="Bitmap"/> from which the data is extracted</param> /// <returns>A byte array containing the raw 24-bit RGB data</returns> private void ExtractImage(Bitmap bitmap) { // This should be a factory when we handle more image types if (bitmap.RawFormat.Equals(ImageFormat.Jpeg)) { JpegParser parser = new JpegParser(m_bitmaps); JpegInfo info = parser.Parse(); m_bitsPerPixel = info.BitsPerSample; m_colorSpace = new ColorSpace(info.ColourSpace); width = info.Width; height = info.Height; // A "no-op" filter since the JPEG data is already compressed filter = new DctFilter(); } else { ExtractOtherImageBits(bitmap); // Performs zip compression filter = new FlateFilter(); } }