/** * Constructor used to attach images to existing PDF. * * @param pdf the page to draw this image on. * @param inputStream the input stream to read the image from. * @param imageType ImageType.JPG, ImageType.PNG and ImageType.BMP. * */ public Image(SortedDictionary <Int32, PDFobj> objects, Stream inputStream, int imageType) { byte[] data; if (imageType == ImageType.JPG) { JPGImage jpg = new JPGImage(inputStream); data = jpg.GetData(); w = jpg.GetWidth(); h = jpg.GetHeight(); if (jpg.GetColorComponents() == 1) { AddImage(objects, data, null, imageType, "DeviceGray", 8); } else if (jpg.GetColorComponents() == 3) { AddImage(objects, data, null, imageType, "DeviceRGB", 8); } else if (jpg.GetColorComponents() == 4) { AddImage(objects, data, null, imageType, "DeviceCMYK", 8); } } else if (imageType == ImageType.PNG) { PNGImage png = new PNGImage(inputStream); data = png.GetData(); w = png.GetWidth(); h = png.GetHeight(); if (png.GetColorType() == 0) { AddImage(objects, data, null, imageType, "DeviceGray", png.GetBitDepth()); } else { if (png.GetBitDepth() == 16) { AddImage(objects, data, null, imageType, "DeviceRGB", 16); } else { AddImage(objects, data, png.GetAlpha(), imageType, "DeviceRGB", 8); } } } else if (imageType == ImageType.BMP) { BMPImage bmp = new BMPImage(inputStream); data = bmp.GetData(); w = bmp.GetWidth(); h = bmp.GetHeight(); AddImage(objects, data, null, imageType, "DeviceRGB", 8); } /* * else if (imageType == ImageType.JET) { * AddImage(pdf, inputStream); * } */ inputStream.Close(); }
/** * The main constructor for the Image class. * * @param pdf the page to draw this image on. * @param inputStream the input stream to read the image from. * @param imageType ImageType.JPG, ImageType.PNG or ImageType.BMP. * */ public Image(PDF pdf, Stream inputStream, int imageType) { byte[] data; if (imageType == ImageType.JPG) { JPGImage jpg = new JPGImage(inputStream); data = jpg.GetData(); w = jpg.GetWidth(); h = jpg.GetHeight(); if (jpg.GetColorComponents() == 1) { AddImage(pdf, data, null, imageType, "DeviceGray", 8); } else if (jpg.GetColorComponents() == 3) { AddImage(pdf, data, null, imageType, "DeviceRGB", 8); } else if (jpg.GetColorComponents() == 4) { AddImage(pdf, data, null, imageType, "DeviceCMYK", 8); } } else if (imageType == ImageType.PNG) { PNGImage png = new PNGImage(inputStream); data = png.GetData(); w = png.GetWidth(); h = png.GetHeight(); if (png.GetColorType() == 0) { AddImage(pdf, data, null, imageType, "DeviceGray", png.GetBitDepth()); } else { if (png.GetBitDepth() == 16) { AddImage(pdf, data, null, imageType, "DeviceRGB", 16); } else { AddImage(pdf, data, png.GetAlpha(), imageType, "DeviceRGB", 8); } } } else if (imageType == ImageType.BMP) { BMPImage bmp = new BMPImage(inputStream); data = bmp.GetData(); w = bmp.GetWidth(); h = bmp.GetHeight(); AddImage(pdf, data, null, imageType, "DeviceRGB", 8); } else if (imageType == ImageType.PNG_STREAM) { AddImage(pdf, inputStream); } inputStream.Dispose(); }
/** * The main constructor for the Image class. * * @param pdf the page to draw this image on. * @param inputStream the input stream to read the image from. * @param imageType ImageType.JPG, ImageType.PNG or ImageType.BMP. * */ public Image(PDF pdf, Stream inputStream, int imageType) { byte[] data; if (imageType == ImageType.JPG) { JPGImage jpg = new JPGImage(inputStream); data = jpg.GetData(); w = jpg.GetWidth(); h = jpg.GetHeight(); if (jpg.GetColorComponents() == 1) { AddImage(pdf, data, null, imageType, "DeviceGray", 8); } else if (jpg.GetColorComponents() == 3) { AddImage(pdf, data, null, imageType, "DeviceRGB", 8); } else if (jpg.GetColorComponents() == 4) { AddImage(pdf, data, null, imageType, "DeviceCMYK", 8); } } else if (imageType == ImageType.PNG) { PNGImage png = new PNGImage(inputStream); data = png.GetData(); w = png.GetWidth(); h = png.GetHeight(); if (png.GetColorType() == 0) { AddImage(pdf, data, null, imageType, "DeviceGray", png.GetBitDepth()); } else { if (png.GetBitDepth() == 16) { AddImage(pdf, data, null, imageType, "DeviceRGB", 16); } else { AddImage(pdf, data, png.GetAlpha(), imageType, "DeviceRGB", 8); } } } else if (imageType == ImageType.BMP) { BMPImage bmp = new BMPImage(inputStream); data = bmp.GetData(); w = bmp.GetWidth(); h = bmp.GetHeight(); AddImage(pdf, data, null, imageType, "DeviceRGB", 8); } else if (imageType == ImageType.JET) { AddImage(pdf, inputStream); } inputStream.Dispose(); }