iTextSharp.text.pdf.codec.BmpImage.GetImage C# (CSharp) Method

GetImage() private method

private GetImage ( ) : Image
return Image
        private Image GetImage()
        {
            byte[] bdata = null; // buffer for byte data
            //short[] sdata = null; // buffer for short data
            //int[] idata = null; // buffer for int data

            //	if (sampleModel.GetDataType() == DataBuffer.TYPE_BYTE)
            //	    bdata = (byte[])((DataBufferByte)tile.GetDataBuffer()).GetData();
            //	else if (sampleModel.GetDataType() == DataBuffer.TYPE_USHORT)
            //	    sdata = (short[])((DataBufferUShort)tile.GetDataBuffer()).GetData();
            //	else if (sampleModel.GetDataType() == DataBuffer.TYPE_INT)
            //	    idata = (int[])((DataBufferInt)tile.GetDataBuffer()).GetData();

            // There should only be one tile.
            switch (imageType) {

                case VERSION_2_1_BIT:
                    // no compression
                    return Read1Bit(3);

                case VERSION_2_4_BIT:
                    // no compression
                    return Read4Bit(3);

                case VERSION_2_8_BIT:
                    // no compression
                    return Read8Bit(3);

                case VERSION_2_24_BIT:
                    // no compression
                    bdata = new byte[width * height * 3];
                    Read24Bit(bdata);
                    return new ImgRaw(width, height, 3, 8, bdata);

                case VERSION_3_1_BIT:
                    // 1-bit images cannot be compressed.
                    return Read1Bit(4);

                case VERSION_3_4_BIT:
                    switch ((int)compression) {
                        case BI_RGB:
                            return Read4Bit(4);

                        case BI_RLE4:
                            return ReadRLE4();

                        default:
                            throw new
                            Exception("Invalid compression specified for BMP file.");
                    }

                case VERSION_3_8_BIT:
                    switch ((int)compression) {
                        case BI_RGB:
                            return Read8Bit(4);

                        case BI_RLE8:
                            return ReadRLE8();

                        default:
                            throw new
                            Exception("Invalid compression specified for BMP file.");
                    }

                case VERSION_3_24_BIT:
                    // 24-bit images are not compressed
                    bdata = new byte[width * height * 3];
                    Read24Bit(bdata);
                    return new ImgRaw(width, height, 3, 8, bdata);

                case VERSION_3_NT_16_BIT:
                    return Read1632Bit(false);

                case VERSION_3_NT_32_BIT:
                    return Read1632Bit(true);

                case VERSION_4_1_BIT:
                    return Read1Bit(4);

                case VERSION_4_4_BIT:
                    switch ((int)compression) {

                        case BI_RGB:
                            return Read4Bit(4);

                        case BI_RLE4:
                            return ReadRLE4();

                        default:
                            throw new
                            Exception("Invalid compression specified for BMP file.");
                    }

                case VERSION_4_8_BIT:
                    switch ((int)compression) {

                        case BI_RGB:
                            return Read8Bit(4);

                        case BI_RLE8:
                            return ReadRLE8();

                        default:
                            throw new
                            Exception("Invalid compression specified for BMP file.");
                    }

                case VERSION_4_16_BIT:
                    return Read1632Bit(false);

                case VERSION_4_24_BIT:
                    bdata = new byte[width * height * 3];
                    Read24Bit(bdata);
                    return new ImgRaw(width, height, 3, 8, bdata);

                case VERSION_4_32_BIT:
                    return Read1632Bit(true);
            }
            return null;
        }

Same methods

BmpImage::GetImage ( Stream isp ) : Image
BmpImage::GetImage ( Stream isp, bool noHeader, int size ) : Image
BmpImage::GetImage ( String file ) : Image
BmpImage::GetImage ( Uri url ) : Image
BmpImage::GetImage ( byte data ) : Image

Usage Example

Example #1
0
 /** Reads a BMP from a stream. The stream is not closed.
 * The BMP may not have a header and be considered as a plain DIB.
 * @param is the stream
 * @param noHeader true to process a plain DIB
 * @param size the size of the DIB. Not used for a BMP
 * @throws IOException on error
 * @return the image
 */    
 public static Image GetImage(Stream isp, bool noHeader, int size) {
     BmpImage bmp = new BmpImage(isp, noHeader, size);
     Image img = bmp.GetImage();
     img.SetDpi((int)((double)bmp.xPelsPerMeter * 0.0254 + 0.5), (int)((double)bmp.yPelsPerMeter * 0.0254 + 0.5));
     img.OriginalType = Image.ORIGINAL_BMP;
     return img;
 }