/** * Adds next GIF frame. The frame is not written immediately, but is actually deferred until the * next frame is received so that timing data can be inserted. Invoking <code>finish()</code> * flushes all frames. If <code>setSize</code> was not invoked, the size of the first image is * used for all subsequent frames. * * @param im BufferedImage containing frame to write. * @throws IOException if there was an IOException writing the GIF data * @throws IllegalArgumentException if this encoder has not been started */ public void addFrame(BufferedImage im) throws IOException { if (!started) { throw new IllegalStateException("AnimatedGifEncoder not started"); } if (!sizeSet) { // use first frame's size setSize(im.getWidth(), im.getHeight()); } image = im; getImagePixels(); // convert to correct format if necessary analyzePixels(); // build color table & map pixels if (firstFrame) { writeLSD(); // logical screen descriptior writePalette(); // global color table if (repeat >= 0) { // use NS app extension to indicate reps writeNetscapeExt(); } } writeGraphicCtrlExt(); // write graphic control extension writeImageDesc(); // image descriptor if (!firstFrame) { writePalette(); // local color table } writePixels(); // encode and write pixel data firstFrame = false; }
/** paint the canvas into a image file of given width and height */ public void writeToImage(String s, int w, int h) { String ext; File f; try { ext = s.substring(s.lastIndexOf(".") + 1); f = new File(s); } catch (Exception e) { System.out.println(e); return; } if (!ext.equals("jpg") && !ext.equals("png")) { System.out.println("Cannot write to file: Illegal extension " + ext); return; } boolean opq = true; if (theOpaque != null) opq = theOpaque; BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setBackground(Color.white); g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1)); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); doBuffer(g2, true, new Rectangle(0, 0, w, h)); try { ImageIO.write(image, ext, f); } catch (Exception e) { System.out.println(e); } }
// buffered images are just better. protected static BufferedImage imageToBufferedImage(Image img) { BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bi.createGraphics(); g2.drawImage(img, null, null); return bi; }
/** * Adds next GIF frame. The frame is not written immediately, but is actually deferred until the * next frame is received so that timing data can be inserted. Invoking <code>finish()</code> * flushes all frames. If <code>setSize</code> was not invoked, the size of the first image is * used for all subsequent frames. * * @param im BufferedImage containing frame to write. * @return true if successful. */ public boolean addFrame(BufferedImage im) { if ((im == null) || !started) { return false; } boolean ok = true; try { if (!sizeSet) { // use first frame's size setSize(im.getWidth(), im.getHeight()); } image = im; getImagePixels(); // convert to correct format if necessary analyzePixels(); // build color table & map pixels if (firstFrame) { writeLSD(); // logical screen descriptior writePalette(); // global color table if (repeat >= 0) { // use NS app extension to indicate reps writeNetscapeExt(); } } writeGraphicCtrlExt(); // write graphic control extension writeImageDesc(); // image descriptor if (!firstFrame) { writePalette(); // local color table } writePixels(); // encode and write pixel data firstFrame = false; } catch (IOException e) { ok = false; } return ok; }
public static int[] decodeImage(BufferedImage img) { /* finds the hidden values in the text file */ int[] a_b, a, b; a = new int[8]; b = new int[8]; a_b = new int[2]; int i; for (i = 0; i < a.length; i++) { int p = img.getRGB(i, i); int[] bin = convertToBinary(p, 32); a[i] = bin[0]; } for (; i < (a.length + b.length); i++) { int p = img.getRGB(i, i); int[] bin = convertToBinary(p, 32); b[i - b.length] = bin[0]; } a_b[0] = convertToDigit(a, 8); a_b[1] = convertToDigit(b, 8); return a_b; }
/** * Save onscreen image to file - suffix must be png, jpg, or gif. * * @param filename the name of the file with one of the required suffixes */ public static void save(String filename) { File file = new File(filename); String suffix = filename.substring(filename.lastIndexOf('.') + 1); // png files if (suffix.toLowerCase().equals("png")) { try { ImageIO.write(onscreenImage, suffix, file); } catch (IOException e) { e.printStackTrace(); } } // need to change from ARGB to RGB for jpeg // reference: // http://archives.java.sun.com/cgi-bin/wa?A2=ind0404&L=java2d-interest&D=0&P=2727 else if (suffix.toLowerCase().equals("jpg")) { WritableRaster raster = onscreenImage.getRaster(); WritableRaster newRaster; newRaster = raster.createWritableChild(0, 0, width, height, 0, 0, new int[] {0, 1, 2}); DirectColorModel cm = (DirectColorModel) onscreenImage.getColorModel(); DirectColorModel newCM = new DirectColorModel( cm.getPixelSize(), cm.getRedMask(), cm.getGreenMask(), cm.getBlueMask()); BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false, null); try { ImageIO.write(rgbBuffer, suffix, file); } catch (IOException e) { e.printStackTrace(); } } else { System.out.println("Invalid image file type: " + suffix); } }
public static BufferedImage encodeImage(String filename, int[] primes) { /* encodes a and b in the image using a sequence. * We are assuming that the image would be big enough * to hold the 16 bits */ BufferedImage img, newimg = null; int[] a = convertToBinary(primes[0], 8); int[] b = convertToBinary(primes[1], 8); int[] a_b = copyBits(a, b); // copy all bits into one array try { img = ImageIO.read(new File(imagePath + filename)); for (int i = 0; i < a_b.length; i++) { int p = img.getRGB(i, i); int[] bin = convertToBinary(p, 32); bin[0] = a_b[i]; int d = convertToDigit(bin, 32); img.setRGB(i, i, d); } ImageIO.write(img, "png", new File(imagePath + "new_" + filename)); newimg = ImageIO.read(new File(imagePath + "new_" + filename)); } catch (IOException e) { System.out.println("ERROR WRITING IMAGE...\n" + e.toString()); System.exit(1); } return newimg; }
public static ArthurImage add(ArthurImage one, ArthurColor two) { BufferedImage image = JavaImageMath.clone(one.bf); double r = two.r.val; double g = two.g.val; double b = two.g.val; WritableRaster raster = image.getRaster(); int[] pixelArray = new int[3]; for (int y = 0; y < raster.getHeight(); y++) { for (int x = 0; x < raster.getWidth(); x++) { pixelArray = raster.getPixel(x, y, pixelArray); pixelArray[0] = (int) (3 * pixelArray[0] + r) / 4; pixelArray[1] = (int) (3 * pixelArray[1] + g) / 4; pixelArray[2] = (int) (3 * pixelArray[2] + b) / 4; raster.setPixel(x, y, pixelArray); } } // save image String outputFn = one.filename.substring(0, one.filename.indexOf(".jpg")) + "+" + // filename can't contain the / or *characters; decide later r + g + b + counter + ".jpg"; counter++; return new ArthurImage(image, outputFn); }
/** * Returns the specified image as icon. * * @param name name of icon * @return icon */ public static ImageIcon icon(final String name) { ImageIcon ii = ICONS.get(name); if (ii != null) return ii; Image img; if (GUIConstants.scale > 1) { // choose large image or none final URL url = GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null; if (url == null) { // resize low-res image if no hi-res image exists img = get(url(name)); final int w = (int) (img.getWidth(null) * GUIConstants.scale); final int h = (int) (img.getHeight(null) * GUIConstants.scale); final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(img, 0, 0, w, h, null); g2.dispose(); img = tmp; } else { img = get(url); } } else { img = get(name); } ii = new ImageIcon(img); ICONS.put(name, ii); return ii; }
public static ArthurImage multiply( ArthurImage one, ArthurNumber two) { // change to ArthurNumber later double f = Math.abs(two.val); // get image BufferedImage image = JavaImageMath.clone(one.bf); // manipulate image WritableRaster raster = image.getRaster(); int width = (int) (raster.getWidth() * f); int height = (int) (raster.getHeight() * f); BufferedImage collage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = collage.createGraphics(); g2d.drawImage(image, 0, 0, width, height, null); g2d.dispose(); // save image String outputFn = one.filename.substring(0, one.filename.indexOf(".jpg")) + "X" + // filename can't contain the / or *characters; decide later f + counter + ".jpg"; counter++; return new ArthurImage(collage, outputFn); }
/** * Convert a source to a BufferedImage. Source supported: * File,BufferedImage,InputStream,URL,ImageInputStream, byte[] * * @param imageType the ImageType to use * @param source source to generate BufferedImage from * @return Enhanced BufferedImage * @throws NullPointerException _ * @throws IOException _ * @throws UnsupportedOperationException throws this is the source is of unsupported type */ public static <T> BufferedImage convertImageType(final ImageType imageType, final T source) throws NullPointerException, IOException, UnsupportedOperationException { if (verifyNotNull(imageType, source)) { BufferedImage target = null; if (source instanceof File) { target = convert(ImageIO.read((File) source), imageType); } else if (source instanceof BufferedImage) { target = convert((BufferedImage) source, imageType); } else if (source instanceof InputStream) { target = convert(ImageIO.read((InputStream) source), imageType); } else if (source instanceof URL) { target = convert(ImageIO.read((URL) source), imageType); } else if (source instanceof ImageInputStream) { target = convert(ImageIO.read((ImageInputStream) source), imageType); } else if (source instanceof byte[]) { final InputStream streamOfInput = new ByteArrayInputStream((byte[]) source); target = convert(ImageIO.read(streamOfInput), imageType); } else { throw new UnsupportedOperationException("%s is not supported. Read JavaDoc."); } if (verifyNotNull(target)) { LOGGER.info( String.format( "Returning requested converted object<%s> as target", target.getClass().getName())); return target; } throw new NullPointerException("Return value was null."); } throw new NullPointerException("Nilled param detected. Please verify your params!"); }
public static ArthurImage add(ArthurImage one, ArthurNumber two) { BufferedImage image = JavaImageMath.clone(one.bf); int num = two.val.intValue(); WritableRaster raster = image.getRaster(); int[] pixelArray = new int[3]; for (int y = 0; y < raster.getHeight(); y++) { for (int x = 0; x < raster.getWidth(); x++) { pixelArray = raster.getPixel(x, y, pixelArray); pixelArray[0] = pixelArray[0] + num; pixelArray[1] = pixelArray[1] + num; pixelArray[2] = pixelArray[2] + num; for (int i = 0; i < 3; i++) { if (pixelArray[i] > 255) { pixelArray[i] = 255; } } raster.setPixel(x, y, pixelArray); } } // save image String outputFn = one.filename.substring(0, one.filename.indexOf(".jpg")) + "+" + // filename can't contain the / or *characters; decide later num + counter + ".jpg"; counter++; return new ArthurImage(image, outputFn); }
private <T> T scaleImageUsingAffineTransformation(final BufferedImage bufferedImage, T target) { BufferedImage destinationImage = generateDestinationImage(); Graphics2D graphics2D = destinationImage.createGraphics(); AffineTransform transformation = AffineTransform.getScaleInstance( ((double) getQualifiedWidth() / bufferedImage.getWidth()), ((double) getQualifiedHeight() / bufferedImage.getHeight())); graphics2D.drawRenderedImage(bufferedImage, transformation); graphics2D.addRenderingHints(retrieveRenderingHints()); try { if (target instanceof File) { LOGGER.info(String.format(M_TARGET_TYPE_OF, "File")); ImageIO.write(destinationImage, imageType.toString(), (File) target); } else if (target instanceof ImageOutputStream) { LOGGER.info(String.format(M_TARGET_TYPE_OF, "ImageOutputStream")); ImageIO.write(destinationImage, imageType.toString(), (ImageOutputStream) target); } else if (target instanceof OutputStream) { LOGGER.info(String.format(M_TARGET_TYPE_OF, "OutputStream")); ImageIO.write(destinationImage, imageType.toString(), (OutputStream) target); } else { target = null; } } catch (IOException e) { e.printStackTrace(); } return target; }
/** Creates a new instance of IDEJRManFramebufferImpl */ public IDEJRManFramebufferImpl(String name, BufferedImage image) { super("JRMan rendered: " + name, true, true, true, true); this.name = name; save.setEnabled(false); imagePanel.setImage(image); imagePanel.addToolbarAction(save); if (image.getType() == BufferedImage.TYPE_INT_ARGB || image.getType() == BufferedImage.TYPE_INT_ARGB_PRE) { imagePanel.setShowTransparencyPattern(true); } getRootPane().setDoubleBuffered(false); getContentPane().add(imagePanel); pack(); ImageResource images = ImageResource.getInstance(); // set the frame icon setFrameIcon(images.getJrMan()); // add this to the IDE desktop MainMenuEventHandlers.getInstance(null) .getIdeInstance() .getWorkspaceDesktop() .addInternalFrame(this, true); }
public static void saveJPG(Image img, String s) { BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bi.createGraphics(); g2.drawImage(img, null, null); FileOutputStream out = null; try { out = new FileOutputStream(s); } catch (java.io.FileNotFoundException io) { System.out.println("File Not Found"); } JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi); param.setQuality(0.5f, false); encoder.setJPEGEncodeParam(param); try { encoder.encode(bi); out.close(); } catch (java.io.IOException io) { System.out.println("IOException"); } }
/** * Appends a frame to the current video. * * @param image the image to append * @return true if image successfully appended */ protected boolean append(Image image) { BufferedImage bi; if (image instanceof BufferedImage) { bi = (BufferedImage) image; } else { bi = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.drawImage(image, 0, 0, null); } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { if (!editing) { videoMedia.beginEdits(); editing = true; } ImageIO.write(bi, "png", out); // $NON-NLS-1$ QTHandle handle = new QTHandle(out.toByteArray()); DataRef dataRef = new DataRef(handle, kDataRefFileExtensionTag, "png"); // $NON-NLS-1$ GraphicsImporter importer = new GraphicsImporter(dataRef); ImageDescription description = importer.getImageDescription(); int duration = (int) (frameDuration * 0.6); videoMedia.addSample( handle, 0, // data offset handle.getSize(), duration, description, 1, // number of samples 0); // key frame?? } catch (Exception ex) { ex.printStackTrace(); return false; } return true; }
public void saveFrametoPNG(String filename) { final int frameWidth = _canvas.getWidth(); final int frameHeight = _canvas.getHeight(); final ByteBuffer pixelsRGB = Direct.newByteBuffer(frameWidth * frameHeight * 3); _canvas.runWithContext( new Runnable() { public void run() { // glPushAttrib(GL_PIXEL_MODE_BIT); glReadBuffer(GL_BACK); glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0, 0, frameWidth, frameHeight, GL_RGB, GL_UNSIGNED_BYTE, pixelsRGB); // glPopAttrib(); } }); int[] pixelInts = new int[frameWidth * frameHeight]; int p = frameWidth * frameHeight * 3; int q; // Index into ByteBuffer int i = 0; // Index into target int[] int w3 = frameWidth * 3; // Number of bytes in each row for (int row = 0; row < frameHeight; row++) { p -= w3; q = p; for (int col = 0; col < frameWidth; col++) { int iR = pixelsRGB.get(q++); int iG = pixelsRGB.get(q++); int iB = pixelsRGB.get(q++); pixelInts[i++] = 0xFF000000 | ((iR & 0x000000FF) << 16) | ((iG & 0x000000FF) << 8) | (iB & 0x000000FF); } } // Create a new BufferedImage from the pixeldata. BufferedImage bufferedImage = new BufferedImage(frameWidth, frameHeight, BufferedImage.TYPE_INT_ARGB); bufferedImage.setRGB(0, 0, frameWidth, frameHeight, pixelInts, 0, frameWidth); try { javax.imageio.ImageIO.write(bufferedImage, "PNG", new File(filename)); } catch (IOException e) { System.out.println("Error: ImageIO.write."); e.printStackTrace(); } /* End code taken from: http://www.felixgers.de/teaching/jogl/imagingProg.html */ /* final BufferedImage image = new BufferedImage( this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics gr = image.getGraphics(); this.printAll(gr); gr.dispose(); try { ImageIO.write(image, "PNG", new File(filename)); } catch (IOException e) { System.out.println( "Error: ImageIO.write." ); e.printStackTrace(); } */ }
public static BufferedImage convertToARGB(BufferedImage image) { BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = newImage.createGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); return newImage; }
public void drawScaledImage(BufferedImage im, int x, int y, int w, int h) { float scaleX = w * 1.0f / im.getWidth(); float scaleY = h * 1.0f / im.getHeight(); AffineTransform tx = new AffineTransform(); tx.scale(scaleX, scaleY); BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); drawImage(im, op, x, y); }
public static BufferedImage resize(BufferedImage image, int width, int height) { BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT); Graphics2D g2d = (Graphics2D) bi.createGraphics(); g2d.addRenderingHints( new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)); g2d.drawImage(image, 0, 0, width, height, null); g2d.dispose(); return bi; }
public static BufferedImage clone(BufferedImage original) { WritableRaster raster = original.getRaster(); BufferedImage clone = new BufferedImage(raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g2d = clone.createGraphics(); g2d.drawImage(original, 0, 0, null); g2d.dispose(); return clone; }
// initialize default image private BufferedImage getDefaultImage(int w, int h) { BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = defaultImage.createGraphics(); graphics2D.setColor(new Color(200, 200, 200)); graphics2D.fillRect(0, 0, w, h); graphics2D.setColor(new Color(130, 130, 130)); graphics2D.drawRect(0, 0, w - 1, h - 1); return defaultImage; }
private void scaleImage() { Image img = back.getScaledInstance(scx(back.getWidth()), scy(back.getHeight()), Image.SCALE_SMOOTH); back = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = back.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); }
/** Asettaa tiilit tiilitaulukkoon. */ private void setTiles() { BufferedImage subimage; for (int col = 0; col < numberOfTilesPerRow; col++) { subimage = tileset.getSubimage(col * tileSize, 0, tileSize, tileSize); tiles[0][col] = new Tile(subimage, Tile.NONSOLID); subimage = tileset.getSubimage(col * tileSize, tileSize, tileSize, tileSize); tiles[1][col] = new Tile(subimage, Tile.SOLID); } }
/** * Turn a (possibly) translucent or indexed image into a display-compatible bitmask image using * the given alpha threshold and render-to-background colour, or display-compatible translucent * image. The alpha values in the image are set to either 0 (below threshold) or 255 (above * threshold). The render-to-background colour bg_col is used to determine how the pixels * overlapping transparent pixels should be rendered. The fast algorithm just sets the colour * behind the transparent pixels in the image (for bitmask source images); the slow algorithm * actually renders the image to a background of bg_col (for translucent sources). * * @param thresh alpha threshold between 0 and 255 * @param fast use fast algorithm (only set bg_col behind transp. pixels) * @param bitmask true=use bitmask, false=use translucent */ public JGImage toDisplayCompatible(int thresh, JGColor bg_col, boolean fast, boolean bitmask) { Color bgcol = new Color(bg_col.r, bg_col.g, bg_col.b); int bgcol_rgb = (bgcol.getRed() << 16) | (bgcol.getGreen() << 8) | bgcol.getBlue(); JGPoint size = getSize(); int[] buffer = getPixels(); // render image to bg depending on bgcol BufferedImage img_bg; if (bitmask) { img_bg = createCompatibleImage(size.x, size.y, Transparency.BITMASK); } else { img_bg = createCompatibleImage(size.x, size.y, Transparency.TRANSLUCENT); } int[] bg_buf; if (!fast) { Graphics g = img_bg.getGraphics(); g.setColor(bgcol); // the docs say I could use bgcol in the drawImage as an // equivalent to the following two lines, but this // doesn't handle translucency properly and is _slower_ g.fillRect(0, 0, size.x, size.y); g.drawImage(img, 0, 0, null); bg_buf = new JREImage(img_bg).getPixels(); } else { bg_buf = buffer; } // g.dispose(); // ColorModel rgb_bitmask = ColorModel.getRGBdefault(); // rgb_bitmask = new PackedColorModel( // rgb_bitmask.getColorSpace(),25,0xff0000,0x00ff00,0x0000ff, // 0x1000000, false, Transparency.BITMASK, DataBuffer.TYPE_INT); // ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean // isAlphaPremultiplied, int trans, int transferType) int[] thrsbuf = new int[size.x * size.y]; for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++) { if (((buffer[y * size.x + x] >> 24) & 0xff) >= thresh) { thrsbuf[y * size.x + x] = bg_buf[y * size.x + x] | (0xff << 24); } else { // explicitly set the colour of the transparent pixel. // This makes a difference when scaling! // thrsbuf[y*size.x+x]=bg_buf[y*size.x+x]&~(0xff<<24); thrsbuf[y * size.x + x] = bgcol_rgb; } } } return new JREImage( output_comp.createImage( new MemoryImageSource( size.x, size.y, // rgb_bitmask, img_bg.getColorModel(), // display compatible bitmask bitmask ? thrsbuf : bg_buf, 0, size.x))); }
@SuppressWarnings("unchecked") private <T> T scaleImageUsingGraphics2D(final BufferedImage bufferedImage, T target) { BufferedImage destinationImage = generateDestinationImage(); Graphics2D graphics2D = destinationImage.createGraphics(); graphics2D.addRenderingHints(retrieveRenderingHints()); graphics2D.drawImage(bufferedImage, O_X, O_Y, getQualifiedWidth(), getQualifiedHeight(), null); graphics2D.dispose(); target = (T) destinationImage; return target; }
public void paint(Graphics g) { // image=tool.getImage(imageName); int h = image2.getHeight(this) / 2; int w = image2.getWidth(this) / 2; g.drawImage(image2, 150, 100, this); // g.drawImage(this.image2, 150+w+30, 100,w,h,this); // g.drawString(imageName, 170, 50); }
private static ImageElement fetchImageProperties( final BufferedImage source, final ImageType imageType, final String id, final Date modifiedDate, final String mimeType) throws NullPointerException, IOException { if (verifyNotNull(source)) { ImageElement image = new ImageElement(); image.setBitDepth( verifyNotNull(source.getColorModel().getPixelSize()) ? source.getColorModel().getPixelSize() : 0); image.setHeight(verifyNotNull(source.getHeight()) ? source.getHeight() : 0); image.setWidth(verifyNotNull(source.getWidth()) ? source.getWidth() : 0); image.setSizeInBytes(determineSizeOfBufferedImage(source, imageType.toString())); image.setCreated(new Date(System.currentTimeMillis())); image.setTransparent( determineTransparencyType(source.getGraphics().getColor().getTransparency())); if (verifyNotNull(modifiedDate)) image.setModified(modifiedDate); image.setId((verifyNotNull(id) ? id : "")); image.setFontType( verifyNotNull(source.getGraphics().getFont()) ? source.getGraphics().getFont() : new Font("Default", 0, 0)); image.setMediaType(MediaType.Missing); return image; } throw new NullPointerException(E_OBJECT_WAS_NULL); }
static BufferedImage addMagnitudes(BufferedImage img1, BufferedImage img2) { BufferedImage dst = new BufferedImage(img1.getWidth(), img1.getHeight(), img1.getType()); for (int y = 0; y < img1.getHeight(); ++y) { for (int x = 0; x < img1.getWidth(); ++x) { int rgb1 = img1.getRGB(x, y); int rgb2 = img2.getRGB(x, y); int r1 = (rgb1 & 0x00FF0000) >> 16; int r2 = (rgb2 & 0x00FF0000) >> 16; int r = (int) (Math.sqrt(r1 * r1 + r2 * r2) / Math.sqrt(2.0)); if (r > 255) r = 255; if (r < 0) r = 0; int g1 = (rgb1 & 0x0000FF00) >> 8; int g2 = (rgb2 & 0x0000FF00) >> 8; int g = (int) (Math.sqrt(g1 * g1 + g2 * g2) / Math.sqrt(2.0)); if (g > 255) g = 255; if (g < 0) g = 0; int b1 = rgb1 & 0x000000FF; int b2 = rgb2 & 0x000000FF; int b = (int) (Math.sqrt(b1 * b1 + b2 * b2) / Math.sqrt(2.0)); if (b > 255) b = 255; if (b < 0) b = 0; int rgb = b + (g << 8) + (r << 16); dst.setRGB(x, y, rgb); } } return dst; }
public void drawTileNumC(int tileNum, int x, int y, Color c, Graphics g) { BufferedImage coloredTile = tiles[tileNum]; for (int i = 0; i < this.tW; i++) { for (int j = 0; j < this.tH; j++) { Color originalColor = new Color(coloredTile.getRGB(i, j), true); Color nc = new Color(c.getRed(), c.getGreen(), c.getBlue(), originalColor.getAlpha()); coloredTile.setRGB(i, j, nc.getRGB()); } } g.drawImage(tiles[tileNum], x, y, null); }