public static BufferedImage createHeatMapImage(HeatMapDataset dataset, PaintScale paintScale) { if (dataset == null) { string str = "Null 'dataset' argument."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else if (paintScale == null) { string str = "Null 'paintScale' argument."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else { int xsampleCount = dataset.getXSampleCount(); int ysampleCount = dataset.getYSampleCount(); BufferedImage bufferedImage = new BufferedImage(xsampleCount, ysampleCount, 2); Graphics2D graphics = bufferedImage.createGraphics(); for (int i1 = 0; i1 < xsampleCount; ++i1) { for (int i2 = 0; i2 < ysampleCount; ++i2) { double zvalue = dataset.getZValue(i1, i2); Paint paint = paintScale.getPaint(zvalue); graphics.setPaint(paint); ((Graphics) graphics).fillRect(i1, ysampleCount - i2 - 1, 1, 1); } } return bufferedImage; } }
public void dispose() { if (this.g2d != null) { this.g2d.dispose(); this.g2d = null; } if (this.bufferedImage != null) { this.bufferedImage.flush(); this.bufferedImage = null; } }
public virtual byte[] encode(BufferedImage bufferedImage) { if (bufferedImage == null) { string str = "Null 'image' argument."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else { PngEncoder.__\u003Cclinit\u003E(); return new PngEncoder((Image) bufferedImage, this.encodingAlpha, 0, this.quality).pngEncode(); } }
public BufferedImageRaster(Sector sector, java.awt.image.BufferedImage bufferedImage, AVList list) { base((null != bufferedImage) ? bufferedImage.getWidth() : 0, (null != bufferedImage) ? bufferedImage.getHeight() : 0, sector, list); if (bufferedImage == null) { String message = Logging.getMessage("nullValue.ImageIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } this.bufferedImage = bufferedImage; }
public virtual void encode(BufferedImage bufferedImage, OutputStream outputStream) { if (bufferedImage == null) { string str = "Null 'image' argument."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else if (outputStream == null) { string str = "Null 'outputStream' argument."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else ImageIO.write((RenderedImage) bufferedImage, "png", outputStream); }
/// <summary> /// Creates a zeroed destination image with the correct size and number of /// bands. </summary> /// <param name="src"> Source image for the filter operation. </param> /// <param name="destCM"> ColorModel of the destination. If null, the /// ColorModel of the source will be used. </param> /// <returns> the zeroed-destination image. </returns> public virtual BufferedImage CreateCompatibleDestImage(BufferedImage src, ColorModel destCM) { BufferedImage image; if (destCM == null) { ColorModel cm = src.ColorModel; image = new BufferedImage(cm, src.Raster.CreateCompatibleWritableRaster(), cm.AlphaPremultiplied, null); } else { int w = src.Width; int h = src.Height; image = new BufferedImage(destCM, destCM.CreateCompatibleWritableRaster(w, h), destCM.AlphaPremultiplied, null); } return(image); }
public override void drawImage(java.awt.image.BufferedImage image, BufferedImageOp op, int x, int y) { if (op == null) { drawImage(image, x, y, null); } else { if (!(op is AffineTransformOp)) { drawImage(op.filter(image, null), x, y, null); } else { Console.WriteLine(new System.Diagnostics.StackTrace()); throw new NotImplementedException(); } } }
public BufferedImageRaster(int width, int height, int transparency, Sector sector) { base(width, height, sector); if (width < 1) { String message = Logging.getMessage("generic.InvalidWidth", width); Logging.logger().severe(message); throw new ArgumentException(message); } if (height < 1) { String message = Logging.getMessage("generic.InvalidHeight", height); Logging.logger().severe(message); throw new ArgumentException(message); } this.bufferedImage = ImageUtil.createCompatibleImage(width, height, transparency); }
/// <summary> /// Creates a zeroed destination image with the correct size and number /// of bands. If destCM is null, an appropriate ColorModel will be used. </summary> /// <param name="src"> Source image for the filter operation. </param> /// <param name="destCM"> ColorModel of the destination. Can be null. </param> /// <returns> a destination <code>BufferedImage</code> with the correct /// size and number of bands. </returns> public virtual BufferedImage CreateCompatibleDestImage(BufferedImage src, ColorModel destCM) { BufferedImage image; int w = src.Width; int h = src.Height; WritableRaster wr = null; if (destCM == null) { destCM = src.ColorModel; // Not much support for ICM if (destCM is IndexColorModel) { destCM = ColorModel.RGBdefault; } else { /* Create destination image as similar to the source * as it possible... */ wr = src.Data.CreateCompatibleWritableRaster(w, h); } } if (wr == null) { /* This is the case when destination color model * was explicitly specified (and it may be not compatible * with source raster structure) or source is indexed image. * We should use destination color model to create compatible * destination raster here. */ wr = destCM.CreateCompatibleWritableRaster(w, h); } image = new BufferedImage(destCM, wr, destCM.AlphaPremultiplied, null); return(image); }
public virtual void encode(BufferedImage bufferedImage, OutputStream outputStream) { if (bufferedImage == null) { string str = "Null 'image' argument."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else if (outputStream == null) { string str = "Null 'outputStream' argument."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else { PngEncoder.__\u003Cclinit\u003E(); PngEncoder pngEncoder = new PngEncoder((Image) bufferedImage, this.encodingAlpha, 0, this.quality); outputStream.write(pngEncoder.pngEncode()); } }
/// <summary> /// Creates a zeroed destination image with the correct size and number of /// bands. A <CODE>RasterFormatException</CODE> may be thrown if the /// transformed width or height is equal to 0. /// <para> /// If <CODE>destCM</CODE> is null, /// an appropriate <CODE>ColorModel</CODE> is used; this /// <CODE>ColorModel</CODE> may have /// an alpha channel even if the source <CODE>ColorModel</CODE> is opaque. /// /// </para> /// </summary> /// <param name="src"> The <CODE>BufferedImage</CODE> to be transformed. </param> /// <param name="destCM"> <CODE>ColorModel</CODE> of the destination. If null, /// an appropriate <CODE>ColorModel</CODE> is used. /// </param> /// <returns> The zeroed destination image. </returns> public virtual BufferedImage CreateCompatibleDestImage(BufferedImage src, ColorModel destCM) { BufferedImage image; Rectangle r = GetBounds2D(src).Bounds; // If r.x (or r.y) is < 0, then we want to only create an image // that is in the positive range. // If r.x (or r.y) is > 0, then we need to create an image that // includes the translation. int w = r.x + r.Width_Renamed; int h = r.y + r.Height_Renamed; if (w <= 0) { throw new RasterFormatException("Transformed width (" + w + ") is less than or equal to 0."); } if (h <= 0) { throw new RasterFormatException("Transformed height (" + h + ") is less than or equal to 0."); } if (destCM == null) { ColorModel cm = src.ColorModel; if (InterpolationType_Renamed != TYPE_NEAREST_NEIGHBOR && (cm is IndexColorModel || cm.Transparency == java.awt.Transparency_Fields.OPAQUE)) { image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); } else { image = new BufferedImage(cm, src.Raster.CreateCompatibleWritableRaster(w, h), cm.AlphaPremultiplied, null); } } else { image = new BufferedImage(destCM, destCM.CreateCompatibleWritableRaster(w, h), destCM.AlphaPremultiplied, null); } return(image); }
/// <summary> /// Rescales the source BufferedImage. /// If the color model in the source image is not the same as that /// in the destination image, the pixels will be converted /// in the destination. If the destination image is null, /// a BufferedImage will be created with the source ColorModel. /// An IllegalArgumentException may be thrown if the number of /// scaling factors/offsets in this object does not meet the /// restrictions stated in the class comments above, or if the /// source image has an IndexColorModel. </summary> /// <param name="src"> the <code>BufferedImage</code> to be filtered </param> /// <param name="dst"> the destination for the filtering operation /// or <code>null</code> </param> /// <returns> the filtered <code>BufferedImage</code>. </returns> /// <exception cref="IllegalArgumentException"> if the <code>ColorModel</code> /// of <code>src</code> is an <code>IndexColorModel</code>, /// or if the number of scaling factors and offsets in this /// <code>RescaleOp</code> do not meet the requirements /// stated in the class comments. </exception> public BufferedImage Filter(BufferedImage src, BufferedImage dst) { ColorModel srcCM = src.ColorModel; ColorModel dstCM; int numBands = srcCM.NumColorComponents; if (srcCM is IndexColorModel) { throw new IllegalArgumentException("Rescaling cannot be " + "performed on an indexed image"); } if (Length != 1 && Length != numBands && Length != srcCM.NumComponents) { throw new IllegalArgumentException("Number of scaling constants " + "does not equal the number of" + " of color or color/alpha " + " components"); } bool needToConvert = false; // Include alpha if (Length > numBands && srcCM.HasAlpha()) { Length = numBands + 1; } int width = src.Width; int height = src.Height; if (dst == null) { dst = CreateCompatibleDestImage(src, null); dstCM = srcCM; } else { if (width != dst.Width) { throw new IllegalArgumentException("Src width (" + width + ") not equal to dst width (" + dst.Width + ")"); } if (height != dst.Height) { throw new IllegalArgumentException("Src height (" + height + ") not equal to dst height (" + dst.Height + ")"); } dstCM = dst.ColorModel; if (srcCM.ColorSpace.Type != dstCM.ColorSpace.Type) { needToConvert = true; dst = CreateCompatibleDestImage(src, null); } } BufferedImage origDst = dst; // // Try to use a native BI rescale operation first // if (ImagingLib.filter(this, src, dst) == null) { // // Native BI rescale failed - convert to rasters // WritableRaster srcRaster = src.Raster; WritableRaster dstRaster = dst.Raster; if (srcCM.HasAlpha()) { if (numBands - 1 == Length || Length == 1) { int minx = srcRaster.MinX; int miny = srcRaster.MinY; int[] bands = new int[numBands - 1]; for (int i = 0; i < numBands - 1; i++) { bands[i] = i; } srcRaster = srcRaster.CreateWritableChild(minx, miny, srcRaster.Width, srcRaster.Height, minx, miny, bands); } } if (dstCM.HasAlpha()) { int dstNumBands = dstRaster.NumBands; if (dstNumBands - 1 == Length || Length == 1) { int minx = dstRaster.MinX; int miny = dstRaster.MinY; int[] bands = new int[numBands - 1]; for (int i = 0; i < numBands - 1; i++) { bands[i] = i; } dstRaster = dstRaster.CreateWritableChild(minx, miny, dstRaster.Width, dstRaster.Height, minx, miny, bands); } } // // Call the raster filter method // Filter(srcRaster, dstRaster); } if (needToConvert) { // ColorModels are not the same ColorConvertOp ccop = new ColorConvertOp(Hints); ccop.Filter(dst, origDst); } return(origDst); }
/// <summary> /// Performs a convolution on BufferedImages. Each component of the /// source image will be convolved (including the alpha component, if /// present). /// If the color model in the source image is not the same as that /// in the destination image, the pixels will be converted /// in the destination. If the destination image is null, /// a BufferedImage will be created with the source ColorModel. /// The IllegalArgumentException may be thrown if the source is the /// same as the destination. </summary> /// <param name="src"> the source <code>BufferedImage</code> to filter </param> /// <param name="dst"> the destination <code>BufferedImage</code> for the /// filtered <code>src</code> </param> /// <returns> the filtered <code>BufferedImage</code> </returns> /// <exception cref="NullPointerException"> if <code>src</code> is <code>null</code> </exception> /// <exception cref="IllegalArgumentException"> if <code>src</code> equals /// <code>dst</code> </exception> /// <exception cref="ImagingOpException"> if <code>src</code> cannot be filtered </exception> public BufferedImage Filter(BufferedImage src, BufferedImage dst) { if (src == null) { throw new NullPointerException("src image is null"); } if (src == dst) { throw new IllegalArgumentException("src image cannot be the " + "same as the dst image"); } bool needToConvert = false; ColorModel srcCM = src.ColorModel; ColorModel dstCM; BufferedImage origDst = dst; // Can't convolve an IndexColorModel. Need to expand it if (srcCM is IndexColorModel) { IndexColorModel icm = (IndexColorModel)srcCM; src = icm.ConvertToIntDiscrete(src.Raster, false); srcCM = src.ColorModel; } if (dst == null) { dst = CreateCompatibleDestImage(src, null); dstCM = srcCM; origDst = dst; } else { dstCM = dst.ColorModel; if (srcCM.ColorSpace.Type != dstCM.ColorSpace.Type) { needToConvert = true; dst = CreateCompatibleDestImage(src, null); dstCM = dst.ColorModel; } else if (dstCM is IndexColorModel) { dst = CreateCompatibleDestImage(src, null); dstCM = dst.ColorModel; } } if (ImagingLib.filter(this, src, dst) == null) { throw new ImagingOpException("Unable to convolve src image"); } if (needToConvert) { ColorConvertOp ccop = new ColorConvertOp(Hints); ccop.Filter(dst, origDst); } else if (origDst != dst) { java.awt.Graphics2D g = origDst.CreateGraphics(); try { g.DrawImage(dst, 0, 0, null); } finally { g.Dispose(); } } return(origDst); }
internal BitmapGraphics(Bitmap bitmap, Object destination, java.awt.Font font, Color fgcolor, Color bgcolor) : base(createGraphics(bitmap), destination, font, fgcolor, bgcolor) { this.bitmap = bitmap; image = destination as BufferedImage; }
public WPIImage(BufferedImage image) { WPIImage wpiImage = this; throw new NoClassDefFoundError("com.googlecode.javacv.cpp.opencv_core$IplImage"); }
/// <summary> /// Creates a zeroed destination image with the correct size and number of /// bands. If destCM is <code>null</code>, an appropriate /// <code>ColorModel</code> will be used. </summary> /// <param name="src"> Source image for the filter operation. </param> /// <param name="destCM"> the destination's <code>ColorModel</code>, which /// can be <code>null</code>. </param> /// <returns> a filtered destination <code>BufferedImage</code>. </returns> public virtual BufferedImage CreateCompatibleDestImage(BufferedImage src, ColorModel destCM) { BufferedImage image; int w = src.Width; int h = src.Height; int transferType = DataBuffer.TYPE_BYTE; if (destCM == null) { ColorModel cm = src.ColorModel; Raster raster = src.Raster; if (cm is ComponentColorModel) { DataBuffer db = raster.DataBuffer; bool hasAlpha = cm.HasAlpha(); bool isPre = cm.AlphaPremultiplied; int trans = cm.Transparency; int[] nbits = null; if (Ltable is ByteLookupTable) { if (db.DataType == db.TYPE_USHORT) { // Dst raster should be of type byte if (hasAlpha) { nbits = new int[2]; if (trans == cm.BITMASK) { nbits[1] = 1; } else { nbits[1] = 8; } } else { nbits = new int[1]; } nbits[0] = 8; } // For byte, no need to change the cm } else if (Ltable is ShortLookupTable) { transferType = DataBuffer.TYPE_USHORT; if (db.DataType == db.TYPE_BYTE) { if (hasAlpha) { nbits = new int[2]; if (trans == cm.BITMASK) { nbits[1] = 1; } else { nbits[1] = 16; } } else { nbits = new int[1]; } nbits[0] = 16; } } if (nbits != null) { cm = new ComponentColorModel(cm.ColorSpace, nbits, hasAlpha, isPre, trans, transferType); } } image = new BufferedImage(cm, cm.CreateCompatibleWritableRaster(w, h), cm.AlphaPremultiplied, null); } else { image = new BufferedImage(destCM, destCM.CreateCompatibleWritableRaster(w, h), destCM.AlphaPremultiplied, null); } return(image); }
public virtual byte[] encode(BufferedImage bufferedImage) { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); this.encode(bufferedImage, (OutputStream) arrayOutputStream); return arrayOutputStream.toByteArray(); }
private BufferedImage NonICCBIFilter(BufferedImage src, ColorSpace srcColorSpace, BufferedImage dst, ColorSpace dstColorSpace) { int w = src.Width; int h = src.Height; ICC_ColorSpace ciespace = (ICC_ColorSpace)ColorSpace.GetInstance(ColorSpace.CS_CIEXYZ); if (dst == null) { dst = CreateCompatibleDestImage(src, null); dstColorSpace = dst.ColorModel.ColorSpace; } else { if ((h != dst.Height) || (w != dst.Width)) { throw new IllegalArgumentException("Width or height of BufferedImages do not match"); } } Raster srcRas = src.Raster; WritableRaster dstRas = dst.Raster; ColorModel srcCM = src.ColorModel; ColorModel dstCM = dst.ColorModel; int srcNumComp = srcCM.NumColorComponents; int dstNumComp = dstCM.NumColorComponents; bool dstHasAlpha = dstCM.HasAlpha(); bool needSrcAlpha = srcCM.HasAlpha() && dstHasAlpha; ColorSpace[] list; if ((CSList == null) && (ProfileList.Length != 0)) { /* possible non-ICC src, some profiles, possible non-ICC dst */ bool nonICCSrc, nonICCDst; ICC_Profile srcProfile, dstProfile; if (!(srcColorSpace is ICC_ColorSpace)) { nonICCSrc = true; srcProfile = ciespace.Profile; } else { nonICCSrc = false; srcProfile = ((ICC_ColorSpace)srcColorSpace).Profile; } if (!(dstColorSpace is ICC_ColorSpace)) { nonICCDst = true; dstProfile = ciespace.Profile; } else { nonICCDst = false; dstProfile = ((ICC_ColorSpace)dstColorSpace).Profile; } /* make a new transform if needed */ if ((ThisTransform == null) || (ThisSrcProfile != srcProfile) || (ThisDestProfile != dstProfile)) { UpdateBITransform(srcProfile, dstProfile); } // process per scanline float maxNum = 65535.0f; // use 16-bit precision in CMM ColorSpace cs; int iccSrcNumComp; if (nonICCSrc) { cs = ciespace; iccSrcNumComp = 3; } else { cs = srcColorSpace; iccSrcNumComp = srcNumComp; } float[] srcMinVal = new float[iccSrcNumComp]; float[] srcInvDiffMinMax = new float[iccSrcNumComp]; for (int i = 0; i < srcNumComp; i++) { srcMinVal[i] = cs.GetMinValue(i); srcInvDiffMinMax[i] = maxNum / (cs.GetMaxValue(i) - srcMinVal[i]); } int iccDstNumComp; if (nonICCDst) { cs = ciespace; iccDstNumComp = 3; } else { cs = dstColorSpace; iccDstNumComp = dstNumComp; } float[] dstMinVal = new float[iccDstNumComp]; float[] dstDiffMinMax = new float[iccDstNumComp]; for (int i = 0; i < dstNumComp; i++) { dstMinVal[i] = cs.GetMinValue(i); dstDiffMinMax[i] = (cs.GetMaxValue(i) - dstMinVal[i]) / maxNum; } float[] dstColor; if (dstHasAlpha) { int size = ((dstNumComp + 1) > 3) ? (dstNumComp + 1) : 3; dstColor = new float[size]; } else { int size = (dstNumComp > 3) ? dstNumComp : 3; dstColor = new float[size]; } short[] srcLine = new short[w * iccSrcNumComp]; short[] dstLine = new short[w * iccDstNumComp]; Object pixel; float[] color; float[] alpha = null; if (needSrcAlpha) { alpha = new float[w]; } int idx; // process each scanline for (int y = 0; y < h; y++) { // convert src scanline pixel = null; color = null; idx = 0; for (int x = 0; x < w; x++) { pixel = srcRas.GetDataElements(x, y, pixel); color = srcCM.GetNormalizedComponents(pixel, color, 0); if (needSrcAlpha) { alpha[x] = color[srcNumComp]; } if (nonICCSrc) { color = srcColorSpace.ToCIEXYZ(color); } for (int i = 0; i < iccSrcNumComp; i++) { srcLine[idx++] = (short)((color[i] - srcMinVal[i]) * srcInvDiffMinMax[i] + 0.5f); } } // color convert srcLine to dstLine ThisTransform.colorConvert(srcLine, dstLine); // convert dst scanline pixel = null; idx = 0; for (int x = 0; x < w; x++) { for (int i = 0; i < iccDstNumComp; i++) { dstColor[i] = ((float)(dstLine[idx++] & 0xffff)) * dstDiffMinMax[i] + dstMinVal[i]; } if (nonICCDst) { color = srcColorSpace.FromCIEXYZ(dstColor); for (int i = 0; i < dstNumComp; i++) { dstColor[i] = color[i]; } } if (needSrcAlpha) { dstColor[dstNumComp] = alpha[x]; } else if (dstHasAlpha) { dstColor[dstNumComp] = 1.0f; } pixel = dstCM.GetDataElements(dstColor, 0, pixel); dstRas.SetDataElements(x, y, pixel); } } } else { /* possible non-ICC src, possible CSList, possible non-ICC dst */ // process per pixel int numCS; if (CSList == null) { numCS = 0; } else { numCS = CSList.Length; } float[] dstColor; if (dstHasAlpha) { dstColor = new float[dstNumComp + 1]; } else { dstColor = new float[dstNumComp]; } Object spixel = null; Object dpixel = null; float[] color = null; float[] tmpColor; // process each pixel for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { spixel = srcRas.GetDataElements(x, y, spixel); color = srcCM.GetNormalizedComponents(spixel, color, 0); tmpColor = srcColorSpace.ToCIEXYZ(color); for (int i = 0; i < numCS; i++) { tmpColor = CSList[i].FromCIEXYZ(tmpColor); tmpColor = CSList[i].ToCIEXYZ(tmpColor); } tmpColor = dstColorSpace.FromCIEXYZ(tmpColor); for (int i = 0; i < dstNumComp; i++) { dstColor[i] = tmpColor[i]; } if (needSrcAlpha) { dstColor[dstNumComp] = color[srcNumComp]; } else if (dstHasAlpha) { dstColor[dstNumComp] = 1.0f; } dpixel = dstCM.GetDataElements(dstColor, 0, dpixel); dstRas.SetDataElements(x, y, dpixel); } } } return(dst); }
/// <summary> /// Transforms the source <CODE>BufferedImage</CODE> and stores the results /// in the destination <CODE>BufferedImage</CODE>. /// If the color models for the two images do not match, a color /// conversion into the destination color model is performed. /// If the destination image is null, /// a <CODE>BufferedImage</CODE> is created with the source /// <CODE>ColorModel</CODE>. /// <para> /// The coordinates of the rectangle returned by /// <code>getBounds2D(BufferedImage)</code> /// are not necessarily the same as the coordinates of the /// <code>BufferedImage</code> returned by this method. If the /// upper-left corner coordinates of the rectangle are /// negative then this part of the rectangle is not drawn. If the /// upper-left corner coordinates of the rectangle are positive /// then the filtered image is drawn at that position in the /// destination <code>BufferedImage</code>. /// </para> /// <para> /// An <CODE>IllegalArgumentException</CODE> is thrown if the source is /// the same as the destination. /// /// </para> /// </summary> /// <param name="src"> The <CODE>BufferedImage</CODE> to transform. </param> /// <param name="dst"> The <CODE>BufferedImage</CODE> in which to store the results /// of the transformation. /// </param> /// <returns> The filtered <CODE>BufferedImage</CODE>. </returns> /// <exception cref="IllegalArgumentException"> if <code>src</code> and /// <code>dst</code> are the same </exception> /// <exception cref="ImagingOpException"> if the image cannot be transformed /// because of a data-processing error that might be /// caused by an invalid image format, tile format, or /// image-processing operation, or any other unsupported /// operation. </exception> public BufferedImage Filter(BufferedImage src, BufferedImage dst) { if (src == null) { throw new NullPointerException("src image is null"); } if (src == dst) { throw new IllegalArgumentException("src image cannot be the " + "same as the dst image"); } bool needToConvert = false; ColorModel srcCM = src.ColorModel; ColorModel dstCM; BufferedImage origDst = dst; if (dst == null) { dst = CreateCompatibleDestImage(src, null); dstCM = srcCM; origDst = dst; } else { dstCM = dst.ColorModel; if (srcCM.ColorSpace.Type != dstCM.ColorSpace.Type) { int type = Xform.Type; bool needTrans = ((type & (Xform.TYPE_MASK_ROTATION | Xform.TYPE_GENERAL_TRANSFORM)) != 0); if (!needTrans && type != Xform.TYPE_TRANSLATION && type != Xform.TYPE_IDENTITY) { double[] mtx = new double[4]; Xform.GetMatrix(mtx); // Check out the matrix. A non-integral scale will force ARGB // since the edge conditions can't be guaranteed. needTrans = (mtx[0] != (int)mtx[0] || mtx[3] != (int)mtx[3]); } if (needTrans && srcCM.Transparency == java.awt.Transparency_Fields.OPAQUE) { // Need to convert first ColorConvertOp ccop = new ColorConvertOp(Hints); BufferedImage tmpSrc = null; int sw = src.Width; int sh = src.Height; if (dstCM.Transparency == java.awt.Transparency_Fields.OPAQUE) { tmpSrc = new BufferedImage(sw, sh, BufferedImage.TYPE_INT_ARGB); } else { WritableRaster r = dstCM.CreateCompatibleWritableRaster(sw, sh); tmpSrc = new BufferedImage(dstCM, r, dstCM.AlphaPremultiplied, null); } src = ccop.Filter(src, tmpSrc); } else { needToConvert = true; dst = CreateCompatibleDestImage(src, null); } } } if (InterpolationType_Renamed != TYPE_NEAREST_NEIGHBOR && dst.ColorModel is IndexColorModel) { dst = new BufferedImage(dst.Width, dst.Height, BufferedImage.TYPE_INT_ARGB); } if (ImagingLib.filter(this, src, dst) == null) { throw new ImagingOpException("Unable to transform src image"); } if (needToConvert) { ColorConvertOp ccop = new ColorConvertOp(Hints); ccop.Filter(dst, origDst); } else if (origDst != dst) { java.awt.Graphics2D g = origDst.CreateGraphics(); try { g.Composite = AlphaComposite.Src; g.DrawImage(dst, 0, 0, null); } finally { g.Dispose(); } } return(origDst); }
/// <summary> /// Renders a <code>BufferedImage</code> that is /// filtered with a /// <A HREF="../../java/awt/image/BufferedImageOp.html" title="interface in java.awt.image"><CODE>BufferedImageOp</CODE></A>. /// </summary> abstract public void drawImage(BufferedImage @img, BufferedImageOp @op, int @x, int @y);
public static void writeBufferedImageAsPNG(OutputStream @out, BufferedImage image, bool encodeAlpha, int compression) { int num = encodeAlpha ? 1 : 0; EncoderUtil.writeBufferedImage(image, "png", @out, (float) compression, num != 0); }
public static byte[] encodeAsPNG(BufferedImage image) { return EncoderUtil.encode(image, "png"); }
public static byte[] encodeAsPNG(BufferedImage image, bool encodeAlpha, int compression) { int num = encodeAlpha ? 1 : 0; return EncoderUtil.encode(image, "png", (float) compression, num != 0); }
public static void writeBufferedImageAsPNG(OutputStream @out, BufferedImage image) { EncoderUtil.writeBufferedImage(image, "png", @out); }
public static void writeBufferedImageAsJPEG(OutputStream @out, BufferedImage image) { ChartUtilities.writeBufferedImageAsJPEG(@out, 0.75f, image); }
public static void writeScaledChartAsPNG(OutputStream @out, JFreeChart chart, int width, int height, int widthScaleFactor, int heightScaleFactor) { if (@out == null) { string str = "Null 'out' argument."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else if (chart == null) { string str = "Null 'chart' argument."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else { double num1 = (double) (width * widthScaleFactor); double num2 = (double) (height * heightScaleFactor); double num3 = (double) width; double num4 = (double) height; int num5 = 0; if (widthScaleFactor != 1 || heightScaleFactor != 1) num5 = 1; double num6 = num1 / num3; double num7 = num2 / num4; BufferedImage image = new BufferedImage(ByteCodeHelper.d2i(num1), ByteCodeHelper.d2i(num2), 2); Graphics2D graphics = image.createGraphics(); if (num5 != 0) { AffineTransform transform = graphics.getTransform(); graphics.transform(AffineTransform.getScaleInstance(num6, num7)); chart.draw(graphics, (Rectangle2D) new Rectangle2D.Double(0.0, 0.0, num3, num4), (Point2D) null, (ChartRenderingInfo) null); graphics.setTransform(transform); ((Graphics) graphics).dispose(); } else chart.draw(graphics, (Rectangle2D) new Rectangle2D.Double(0.0, 0.0, num3, num4), (Point2D) null, (ChartRenderingInfo) null); @out.write(ChartUtilities.encodeAsPNG(image)); } }
public static void writeBufferedImageAsJPEG(OutputStream @out, float quality, BufferedImage image) { EncoderUtil.writeBufferedImage(image, "jpeg", @out, quality); }
private BufferedImage createTransparentImage([In] int obj0, [In] int obj1) { BufferedImage bufferedImage = new BufferedImage(obj0, obj1, 2); int[] rgb = bufferedImage.getRGB(0, 0, obj0, obj1, (int[]) null, 0, obj0); Arrays.fill(rgb, 0); bufferedImage.setRGB(0, 0, obj0, obj1, rgb, 0, obj0); return bufferedImage; }
/// <summary> /// Returns the bounding box of the filtered destination image. Since /// this is not a geometric operation, the bounding box does not /// change. /// </summary> public Rectangle2D GetBounds2D(BufferedImage src) { return(GetBounds2D(src.Raster)); }
public static byte[] encode(BufferedImage image, string format, float quality) { return ImageEncoderFactory.newInstance(format, quality).encode(image); }
public override void setPaint(java.awt.Paint paint) { if (paint is java.awt.Color) { setColor((java.awt.Color)paint); return; } if (paint == null || this.javaPaint == paint) { return; } this.javaPaint = paint; if (paint is java.awt.GradientPaint) { java.awt.GradientPaint gradient = (java.awt.GradientPaint)paint; LinearGradientBrush linear; if (gradient.isCyclic()) { linear = new LinearGradientBrush( J2C.ConvertPoint(gradient.getPoint1()), J2C.ConvertPoint(gradient.getPoint2()), composite.GetColor(gradient.getColor1()), composite.GetColor(gradient.getColor2())); } else { //HACK because .NET does not support continue gradient like Java else Tile Gradient //that we receize the rectangle very large (factor z) and set 4 color values // a exact solution will calculate the size of the Graphics with the current transform Color color1 = composite.GetColor(gradient.getColor1()); Color color2 = composite.GetColor(gradient.getColor2()); float x1 = (float)gradient.getPoint1().getX(); float x2 = (float)gradient.getPoint2().getX(); float y1 = (float)gradient.getPoint1().getY(); float y2 = (float)gradient.getPoint2().getY(); float diffX = x2 - x1; float diffY = y2 - y1; const float z = 60; //HACK zoom factor, with a larger factor .NET will make the gradient wider. linear = new LinearGradientBrush( new PointF(x1 - z * diffX, y1 - z * diffY), new PointF(x2 + z * diffX, y2 + z * diffY), color1, color1); ColorBlend colorBlend = new ColorBlend(4); Color[] colors = colorBlend.Colors; colors[0] = colors[1] = color1; colors[2] = colors[3] = color2; float[] positions = colorBlend.Positions; positions[1] = z / (2 * z + 1); positions[2] = (z + 1) / (2 * z + 1); positions[3] = 1.0f; linear.InterpolationColors = colorBlend; } linear.WrapMode = WrapMode.TileFlipXY; brush = linear; pen.Brush = brush; return; } if (paint is java.awt.TexturePaint) { java.awt.TexturePaint texture = (java.awt.TexturePaint)paint; Bitmap txtr = J2C.ConvertImage(texture.getImage()); java.awt.geom.Rectangle2D anchor = texture.getAnchorRect(); TextureBrush txtBrush; brush = txtBrush = new TextureBrush(txtr, new Rectangle(0, 0, txtr.Width, txtr.Height), composite.GetImageAttributes()); txtBrush.TranslateTransform((float)anchor.getX(), (float)anchor.getY()); txtBrush.ScaleTransform((float)anchor.getWidth() / txtr.Width, (float)anchor.getHeight() / txtr.Height); txtBrush.WrapMode = WrapMode.Tile; pen.Brush = brush; return; } if (paint is java.awt.LinearGradientPaint) { java.awt.LinearGradientPaint gradient = (java.awt.LinearGradientPaint)paint; PointF start = J2C.ConvertPoint(gradient.getStartPoint()); PointF end = J2C.ConvertPoint(gradient.getEndPoint()); java.awt.Color[] javaColors = gradient.getColors(); ColorBlend colorBlend; Color[] colors; bool noCycle = gradient.getCycleMethod() == java.awt.MultipleGradientPaint.CycleMethod.NO_CYCLE; if (noCycle) { //HACK because .NET does not support continue gradient like Java else Tile Gradient //that we receize the rectangle very large (factor z) and set 2 additional color values //an exact solution will calculate the size of the Graphics with the current transform float diffX = end.X - start.X; float diffY = end.Y - start.Y; SizeF size = GetSize(); //HACK zoom factor, with a larger factor .NET will make the gradient wider. float z = Math.Min(10, Math.Max(size.Width / diffX, size.Height / diffY)); start.X -= z * diffX; start.Y -= z * diffY; end.X += z * diffX; end.Y += z * diffY; colorBlend = new ColorBlend(javaColors.Length + 2); colors = colorBlend.Colors; float[] fractions = gradient.getFractions(); float[] positions = colorBlend.Positions; for (int i = 0; i < javaColors.Length; i++) { colors[i + 1] = composite.GetColor(javaColors[i]); positions[i + 1] = (z + fractions[i]) / (2 * z + 1); } colors[0] = colors[1]; colors[colors.Length - 1] = colors[colors.Length - 2]; positions[positions.Length - 1] = 1.0f; } else { colorBlend = new ColorBlend(javaColors.Length); colors = colorBlend.Colors; colorBlend.Positions = gradient.getFractions(); for (int i = 0; i < javaColors.Length; i++) { colors[i] = composite.GetColor(javaColors[i]); } } LinearGradientBrush linear = new LinearGradientBrush(start, end, colors[0], colors[colors.Length - 1]); linear.InterpolationColors = colorBlend; switch (gradient.getCycleMethod().ordinal()) { case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.NO_CYCLE: case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.REFLECT: linear.WrapMode = WrapMode.TileFlipXY; break; case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.REPEAT: linear.WrapMode = WrapMode.Tile; break; } brush = linear; pen.Brush = brush; return; } if (paint is java.awt.RadialGradientPaint ) { java.awt.RadialGradientPaint gradient = (java.awt.RadialGradientPaint)paint; GraphicsPath path = new GraphicsPath(); SizeF size = GetSize(); PointF center = J2C.ConvertPoint(gradient.getCenterPoint()); float radius = gradient.getRadius(); int factor = (int)Math.Ceiling(Math.Max(size.Width, size.Height) / radius); float diameter = radius * factor; path.AddEllipse(center.X - diameter, center.Y - diameter, diameter * 2, diameter * 2); java.awt.Color[] javaColors = gradient.getColors(); float[] fractions = gradient.getFractions(); int length = javaColors.Length; ColorBlend colorBlend = new ColorBlend(length * factor); Color[] colors = colorBlend.Colors; float[] positions = colorBlend.Positions; for (int c = 0, j = length - 1; j >= 0; ) { positions[c] = (1 - fractions[j]) / factor; colors[c++] = composite.GetColor(javaColors[j--]); } java.awt.MultipleGradientPaint.CycleMethod.__Enum cycle = (java.awt.MultipleGradientPaint.CycleMethod.__Enum)gradient.getCycleMethod().ordinal(); for (int f = 1; f < factor; f++) { int off = f * length; for (int c = 0, j = length - 1; j >= 0; j--, c++) { switch (cycle) { case java.awt.MultipleGradientPaint.CycleMethod.__Enum.REFLECT: if (f % 2 == 0) { positions[off + c] = (f + 1 - fractions[j]) / factor; colors[off + c] = colors[c]; } else { positions[off + c] = (f + fractions[c]) / factor; colors[off + c] = colors[j]; } break; case java.awt.MultipleGradientPaint.CycleMethod.__Enum.NO_CYCLE: positions[off + c] = (f + 1 - fractions[j]) / factor; break; default: //CycleMethod.REPEAT positions[off + c] = (f + 1 - fractions[j]) / factor; colors[off + c] = colors[c]; break; } } } if (cycle == java.awt.MultipleGradientPaint.CycleMethod.__Enum.NO_CYCLE && factor > 1) { Array.Copy(colors, 0, colors, colors.Length - length, length); Color color = colors[length - 1]; for (int i = colors.Length - length - 1; i >= 0; i--) { colors[i] = color; } } PathGradientBrush pathBrush = new PathGradientBrush(path); pathBrush.CenterPoint = center; pathBrush.InterpolationColors = colorBlend; brush = pathBrush; pen.Brush = brush; return; } //generic paint to brush conversion for custom paints //the tranform of the graphics should not change between the creation and it usage using (Matrix transform = g.Transform) { SizeF size = GetSize(); int width = (int)size.Width; int height = (int)size.Height; java.awt.Rectangle bounds = new java.awt.Rectangle(0, 0, width, height); java.awt.PaintContext context = paint.createContext(ColorModel.getRGBdefault(), bounds, bounds, C2J.ConvertMatrix(transform), getRenderingHints()); WritableRaster raster = (WritableRaster)context.getRaster(0, 0, width, height); BufferedImage txtrImage = new BufferedImage(context.getColorModel(), raster, true, null); Bitmap txtr = J2C.ConvertImage(txtrImage); TextureBrush txtBrush; brush = txtBrush = new TextureBrush(txtr, new Rectangle(0, 0, width, height), composite.GetImageAttributes()); transform.Invert(); txtBrush.Transform = transform; txtBrush.WrapMode = WrapMode.Tile; pen.Brush = brush; return; } }
private BufferedImage ICCBIFilter(BufferedImage src, ColorSpace srcColorSpace, BufferedImage dest, ColorSpace destColorSpace) { int nProfiles = ProfileList.Length; ICC_Profile srcProfile = null, destProfile = null; srcProfile = ((ICC_ColorSpace)srcColorSpace).Profile; if (dest == null) { /* last profile in the list defines * the output color space */ if (nProfiles == 0) { throw new IllegalArgumentException("Destination ColorSpace is undefined"); } destProfile = ProfileList [nProfiles - 1]; dest = CreateCompatibleDestImage(src, null); } else { if (src.Height != dest.Height || src.Width != dest.Width) { throw new IllegalArgumentException("Width or height of BufferedImages do not match"); } destProfile = ((ICC_ColorSpace)destColorSpace).Profile; } /* Checking if all profiles in the transform sequence are the same. * If so, performing just copying the data. */ if (srcProfile == destProfile) { bool noTrans = true; for (int i = 0; i < nProfiles; i++) { if (srcProfile != ProfileList[i]) { noTrans = false; break; } } if (noTrans) { Graphics2D g = dest.CreateGraphics(); try { g.DrawImage(src, 0, 0, null); } finally { g.Dispose(); } return(dest); } } /* make a new transform if needed */ if ((ThisTransform == null) || (ThisSrcProfile != srcProfile) || (ThisDestProfile != destProfile)) { UpdateBITransform(srcProfile, destProfile); } /* color convert the image */ ThisTransform.colorConvert(src, dest); return(dest); }
public static byte[] encode(BufferedImage image, string format, bool encodeAlpha) { int num = encodeAlpha ? 1 : 0; return ImageEncoderFactory.newInstance(format, num != 0).encode(image); }
public PlainImage Clone(bool cloneImage) { awt.Image img = NativeImage; awt.Image [] th = _thumbnails; if (cloneImage) { img = new BufferedImage( ((BufferedImage)NativeObject).getColorModel(), ((BufferedImage)NativeObject).copyData(null), ((BufferedImage)NativeObject).isAlphaPremultiplied(), null); if (Thumbnails != null) { th = new java.awt.Image[ Thumbnails.Length ]; for (int i=0; i < Thumbnails.Length; i++) { th[i] = new BufferedImage( ((BufferedImage)Thumbnails[i]).getColorModel(), ((BufferedImage)Thumbnails[i]).copyData(null), ((BufferedImage)Thumbnails[i]).isAlphaPremultiplied(), null); } } } return new PlainImage( img, th, ImageFormat, HorizontalResolution, VerticalResolution, Dimension ); }
/// <summary> /// Writes the <tt>InfoHeader</tt> structure to output /// /// </summary> private void WriteInfoHeader(BufferedImage img) { // Size of InfoHeader structure = 40 writer.Write(40); // Width writer.Write(img.getWidth()); // Height writer.Write(img.getHeight() * 2); // Planes (=1) writer.Write((short)1); // Bit count writer.Write((short)img.getColorModel().getPixelSize()); // Compression writer.Write(0); // Image size - compressed size of image or 0 if Compression = 0 writer.Write(0); // horizontal resolution pixels/meter writer.Write(0); // vertical resolution pixels/meter writer.Write(0); // Colors used - number of colors actually used writer.Write(0); // Colors important - number of important colors 0 = all writer.Write(0); }
/// <summary> /// Performs a lookup operation on a <code>BufferedImage</code>. /// If the color model in the source image is not the same as that /// in the destination image, the pixels will be converted /// in the destination. If the destination image is <code>null</code>, /// a <code>BufferedImage</code> will be created with an appropriate /// <code>ColorModel</code>. An <code>IllegalArgumentException</code> /// might be thrown if the number of arrays in the /// <code>LookupTable</code> does not meet the restrictions /// stated in the class comment above, or if the source image /// has an <code>IndexColorModel</code>. </summary> /// <param name="src"> the <code>BufferedImage</code> to be filtered </param> /// <param name="dst"> the <code>BufferedImage</code> in which to /// store the results of the filter operation </param> /// <returns> the filtered <code>BufferedImage</code>. </returns> /// <exception cref="IllegalArgumentException"> if the number of arrays in the /// <code>LookupTable</code> does not meet the restrictions /// described in the class comments, or if the source image /// has an <code>IndexColorModel</code>. </exception> public BufferedImage Filter(BufferedImage src, BufferedImage dst) { ColorModel srcCM = src.ColorModel; int numBands = srcCM.NumColorComponents; ColorModel dstCM; if (srcCM is IndexColorModel) { throw new IllegalArgumentException("LookupOp cannot be " + "performed on an indexed image"); } int numComponents = Ltable.NumComponents; if (numComponents != 1 && numComponents != srcCM.NumComponents && numComponents != srcCM.NumColorComponents) { throw new IllegalArgumentException("Number of arrays in the " + " lookup table (" + numComponents + " is not compatible with the " + " src image: " + src); } bool needToConvert = false; int width = src.Width; int height = src.Height; if (dst == null) { dst = CreateCompatibleDestImage(src, null); dstCM = srcCM; } else { if (width != dst.Width) { throw new IllegalArgumentException("Src width (" + width + ") not equal to dst width (" + dst.Width + ")"); } if (height != dst.Height) { throw new IllegalArgumentException("Src height (" + height + ") not equal to dst height (" + dst.Height + ")"); } dstCM = dst.ColorModel; if (srcCM.ColorSpace.Type != dstCM.ColorSpace.Type) { needToConvert = true; dst = CreateCompatibleDestImage(src, null); } } BufferedImage origDst = dst; if (ImagingLib.filter(this, src, dst) == null) { // Do it the slow way WritableRaster srcRaster = src.Raster; WritableRaster dstRaster = dst.Raster; if (srcCM.HasAlpha()) { if (numBands - 1 == numComponents || numComponents == 1) { int minx = srcRaster.MinX; int miny = srcRaster.MinY; int[] bands = new int[numBands - 1]; for (int i = 0; i < numBands - 1; i++) { bands[i] = i; } srcRaster = srcRaster.CreateWritableChild(minx, miny, srcRaster.Width, srcRaster.Height, minx, miny, bands); } } if (dstCM.HasAlpha()) { int dstNumBands = dstRaster.NumBands; if (dstNumBands - 1 == numComponents || numComponents == 1) { int minx = dstRaster.MinX; int miny = dstRaster.MinY; int[] bands = new int[numBands - 1]; for (int i = 0; i < numBands - 1; i++) { bands[i] = i; } dstRaster = dstRaster.CreateWritableChild(minx, miny, dstRaster.Width, dstRaster.Height, minx, miny, bands); } } Filter(srcRaster, dstRaster); } if (needToConvert) { // ColorModels are not the same ColorConvertOp ccop = new ColorConvertOp(Hints); ccop.Filter(dst, origDst); } return(origDst); }
/// <summary> /// Writes the <tt>IconEntry</tt> structure to output /// </summary> private int WriteIconEntry(BufferedImage img, int fileOffset) { // Width 1 byte Cursor Width (16, 32 or 64) int width = img.getWidth(); writer.Write((byte)(width == 256 ? 0 : width)); // Height 1 byte Cursor Height (16, 32 or 64 , most commonly = Width) int height = img.getHeight(); writer.Write((byte)(height == 256 ? 0 : height)); // ColorCount 1 byte Number of Colors (2,16, 0=256) short BitCount = (short)img.getColorModel().getPixelSize(); int NumColors = 1 << (BitCount == 32 ? 24 : (int)BitCount); byte ColorCount = (byte)(NumColors >= 256 ? 0 : NumColors); writer.Write((byte)ColorCount); // Reserved 1 byte =0 writer.Write((byte)0); // Planes 2 byte =1 writer.Write((short)1); // BitCount 2 byte bits per pixel (1, 4, 8) writer.Write((short)BitCount); // SizeInBytes 4 byte Size of (InfoHeader + ANDbitmap + XORbitmap) int cmapSize = GetColorMapSize(BitCount); int xorSize = GetBitmapSize(width, height, BitCount); int andSize = GetBitmapSize(width, height, 1); int size = 40 + cmapSize + xorSize + andSize; writer.Write(size); // FileOffset 4 byte FilePos, where InfoHeader starts writer.Write(fileOffset); return size; }
public override void propertyChanged(Property property) { if (property != this.__\u003C\u003Eimg) return; try { File.__\u003Cclinit\u003E(); this.image = ImageIO.read(new File((string) this.__\u003C\u003Eimg.getValue())); Dimension.__\u003Cclinit\u003E(); ((JComponent) this).setPreferredSize(new Dimension(this.image.getWidth(), this.image.getHeight())); goto label_5; } catch (IOException ex) { } this.image = (BufferedImage) null; JOptionPane.showMessageDialog((Component) this, (object) "Invalid File Type.", "Input Error", 2); ((JComponent) this).setPreferredSize(new Dimension(100, 100)); label_5: ((JComponent) this).revalidate(); ((Component) this).repaint(); }
public static void writeBufferedImage(BufferedImage image, string format, OutputStream outputStream, bool encodeAlpha) { int num = encodeAlpha ? 1 : 0; ImageEncoderFactory.newInstance(format, num != 0).encode(image, outputStream); }
public WPIColorImage(BufferedImage imageSrc) : base(imageSrc) { GC.KeepAlive((object) this); }
public BufferedImageRaster(Sector sector, java.awt.image.BufferedImage bufferedImage) { this(sector, bufferedImage, null); }
/// <summary> /// Encodes the <em>AND</em> bitmap for the given image according the its /// alpha channel (transparency) and writes it to the given output. /// </summary> /// <param name="img"> /// the image to encode as the <em>AND</em> bitmap. </param> private void WriteAndBitmap(BufferedImage img) { WritableRaster alpha = img.getAlphaRaster(); // indexed transparency (eg. GIF files) if (img.getColorModel() is IndexColorModel && img.getColorModel().hasAlpha()) { int w = img.getWidth(); int h = img.getHeight(); int bytesPerLine = GetBytesPerLine1(w); byte[] line = new byte[bytesPerLine]; IndexColorModel icm = (IndexColorModel)img.getColorModel(); Raster raster = img.getRaster(); for (int y = h - 1; y >= 0; y--) { for (int x = 0; x < w; x++) { int bi = x / 8; int i = x % 8; // int a = alpha.getSample(x, y, 0); int p = raster.getSample(x, y, 0); int a = icm.getAlpha(p); // invert bit since and mask is applied to xor mask int b = ~a & 1; line[bi] = SetBit(line[bi], i, b); } writer.Write(line); } } // no transparency else if (alpha == null) { int h = img.getHeight(); int w = img.getWidth(); // calculate number of bytes per line, including 32-bit padding int bytesPerLine = GetBytesPerLine1(w); byte[] line = new byte[bytesPerLine]; for (int i = 0; i < bytesPerLine; i++) { line[i] = (byte)0; } for (int y = h - 1; y >= 0; y--) { writer.Write(line); } } // transparency (ARGB, etc. eg. PNG) else { int w = img.getWidth(); int h = img.getHeight(); int bytesPerLine = GetBytesPerLine1(w); byte[] line = new byte[bytesPerLine]; for (int y = h - 1; y >= 0; y--) { for (int x = 0; x < w; x++) { int bi = x / 8; int i = x % 8; int a = alpha.getSample(x, y, 0); // invert bit since and mask is applied to xor mask int b = ~a & 1; line[bi] = SetBit(line[bi], i, b); } writer.Write(line); } } }
private void WriteXorBitmap(BufferedImage img) { Raster raster = img.getRaster(); switch (img.getColorModel().getPixelSize()) { case 1: Write1(raster); break; case 4: Write4(raster); break; case 8: Write8(raster); break; case 24: Write24(raster); break; case 32: Raster alpha = img.getAlphaRaster(); Write32(raster, alpha); break; } }
// Create a bitmap with the dimensions of the argument image. Then // create a graphics objects from the bitmap. All paint operations will // then paint the bitmap. public override java.awt.Graphics2D createGraphics(BufferedImage bi) { return new BitmapGraphics(bi.getBitmap()); }
public static void writeBufferedImage(BufferedImage image, string format, OutputStream outputStream, float quality) { ImageEncoderFactory.newInstance(format, quality).encode(image, outputStream); }