/** * Converts a {@link Planar} {@link GrayF32} into a BufferedImage. * * @param src Input image. * @param dst Where the converted image is written to. If null a new image is created. * @param orderRgb If applicable, should it change the order of the color bands (assumed RGB or ARGB) into the * order based on BufferedImage.TYPE. Most of the time you want this to be true. * @return Converted image. */ public static BufferedImage convertTo_F32(Planar<GrayF32> src, BufferedImage dst, boolean orderRgb) { dst = checkInputs(src, dst); if( orderRgb ) { src = orderBandsIntoBuffered(src, dst); } try { if (dst.getRaster() instanceof ByteInterleavedRaster && dst.getType() != BufferedImage.TYPE_BYTE_INDEXED ) { ConvertRaster.multToBuffered_F32(src, (ByteInterleavedRaster) dst.getRaster()); } else if (dst.getRaster() instanceof IntegerInterleavedRaster) { ConvertRaster.multToBuffered_F32(src, (IntegerInterleavedRaster) dst.getRaster()); } else { ConvertRaster.multToBuffered_F32(src, dst); } // hack so that it knows the buffer has been modified dst.setRGB(0,0,dst.getRGB(0,0)); } catch( java.security.AccessControlException e) { ConvertRaster.multToBuffered_F32(src, dst); } return dst; }
/** * Converts a {@link Planar} {@link GrayU8} into a BufferedImage. * * @param src Input image. * @param dst Where the converted image is written to. If null a new image is created. * @param orderRgb If applicable, should it change the order of the color bands (assumed RGB or ARGB) into the * order based on BufferedImage.TYPE. Most of the time you want this to be true. * @return Converted image. */ public static BufferedImage convertTo_U8(Planar<GrayU8> src, BufferedImage dst, boolean orderRgb ) { dst = checkInputs(src, dst); if( orderRgb ) { src = orderBandsIntoBuffered(src, dst); } try { if (dst.getRaster() instanceof ByteInterleavedRaster && dst.getType() != BufferedImage.TYPE_BYTE_INDEXED ) { ConvertRaster.multToBuffered_U8(src, (ByteInterleavedRaster) dst.getRaster()); } else if (dst.getRaster() instanceof IntegerInterleavedRaster) { ConvertRaster.multToBuffered_U8(src, (IntegerInterleavedRaster) dst.getRaster()); } else { ConvertRaster.multToBuffered_U8(src, dst); } // hack so that it knows the buffer has been modified dst.setRGB(0,0,dst.getRGB(0,0)); } catch( java.security.AccessControlException e) { ConvertRaster.multToBuffered_U8(src, dst); } return dst; }