bufferedimage

Save buffered image with transparent background

陌路散爱 提交于 2019-12-03 05:16:48
I'm saving the image of a signature as a .jpg picture. I use graphic2d to paint on the image every pixel of the signature (gotten with a signature tablet) and it works perfectly but I'm always gettin a white background. If I want to put the signature on a PDF document, the borders of the white square of the jpg image covers some of the words of the PDF. What I want to get is to save the jpg image with a transparent background, so when I put it on the PDF there are no words covered with the white image background but just the signature lines. This is the code that saves the buffered image. It

Drawing on a buffered image

廉价感情. 提交于 2019-12-02 22:42:35
问题 I am trying to draw on a buffered image. I am able to get the picture on the frame but it doesnt seem to draw on the image. If I use BufferedImage bufferedImage = new BufferedImage(1280, 800,BufferedImage.TYPE_INT_RGB); then it seems to draw the string but I would like to ideally draw on the image as I need to plot some coordinates on the image for a project. Any guidance would be highly appreciated. Excuse the bad indentation import java.awt.Dimension; import java.awt.Graphics; import java

loading BufferedImage with ClassLoader.getResource()

主宰稳场 提交于 2019-12-02 22:29:42
问题 I am trying to load an image file (gif) which is stored locally in the same directory as my Eclipse java project: ref is the relative path where the gif image is stored. public Sprite getSprite(String ref) { BufferedImage sourceImage = null; try { URL url = this.getClass().getClassLoader().getResource(ref); if (url == null) { fail("Can't find ref: "+ref); } sourceImage = ImageIO.read(url); } catch (IOException e) { fail("Failed to load: "+ref); } } The client code that uses the above method

Java: Get the RGBA from a Buffered Image as an Array of Integer

…衆ロ難τιáo~ 提交于 2019-12-02 20:15:52
问题 Given an image file, say of PNG format, how to I get an array of int [r,g,b,a] representing the pixel located at row i, column j? So far I am starting here: private static int[][][] getPixels(BufferedImage image) { final byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); final int width = image.getWidth(); final int height = image.getHeight(); int[][][] result = new int[height][width][4]; // SOLUTION GOES HERE.... } Thanks in advance! 回答1: You need to get the

Image size getting decreased after converting it into byte[] using BufferedImage and ImageIO

爷,独闯天下 提交于 2019-12-02 11:55:03
问题 I am converting an Image into byte[] using following code. public static byte[] extractBytes (String ImageName) throws IOException { ByteArrayOutputStream baos=new ByteArrayOutputStream(); BufferedImage img=ImageIO.read(new File(ImageName)); ImageIO.write(img, "jpg", baos); return baos.toByteArray(); } Now when I am testing my code: public static void main(String[] args) throws IOException { String filepath = "image_old.jpg"; File outp=new File(filepath); System.out.println("Size of original

Can a BufferedImage be written to file any format?

孤人 提交于 2019-12-02 09:33:10
Is it correct that if we have a BufferedImage object in java, we could potentially write it out in ANY format using ImageIO.write (if we have a Writer object for the same)? I tried writing a BufferedImage object into a jpg file, it outputted an empty image file however when i tried writing it in to a png file, it worked fine. A BufferedImage can be written into any format that ImageIO.write supports (that is, has an ImageWriter available), yes. Please show the code if you can't get it to work. 来源: https://stackoverflow.com/questions/2543275/can-a-bufferedimage-be-written-to-file-any-format

Coloring an area of BufferedImage

老子叫甜甜 提交于 2019-12-02 08:41:52
I want to color a sub area of a BufferedImage I have. I am presently doing: public BufferedImage paintSubImage(BufferedImage img, int x, int y, int w, int h) { Graphics g = img.getGraphics(); g.setColor(Color.BLACK); g.fillRect(x,y,w,h); return img; } But I am not able to color it. Am I doing it wrong? Given the fact that there is little or no context to go on, it's difficult to know exactly what's wrong. General rule of thumb though, if you create/open it, you should dispose/close it... import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue;

loading BufferedImage with ClassLoader.getResource()

南笙酒味 提交于 2019-12-02 07:35:23
I am trying to load an image file (gif) which is stored locally in the same directory as my Eclipse java project: ref is the relative path where the gif image is stored. public Sprite getSprite(String ref) { BufferedImage sourceImage = null; try { URL url = this.getClass().getClassLoader().getResource(ref); if (url == null) { fail("Can't find ref: "+ref); } sourceImage = ImageIO.read(url); } catch (IOException e) { fail("Failed to load: "+ref); } } The client code that uses the above method is: public Entity(String ref,int x,int y) { this.sprite = ResourceManager.getSprite("sprites/alien.gif")

extending BufferedImage

一个人想着一个人 提交于 2019-12-02 07:09:45
问题 Why does the following code show a black image instead of the picture? How to properly extend BufferedImage? class SizeOfImage { public static void main(String[] args) throws Exception { URL url = new URL("http://cloudbite.co.uk/wp-content/uploads/2011/03/google-chrome-logo-v1.jpg"); final BufferedImage bi = ImageIO.read(url); final String size = bi.getWidth() + "x" + bi.getHeight(); final CustomImg cstImg = new CustomImg(bi.getWidth(), bi.getHeight(), bi.getType()); SwingUtilities

Printing a BufferedImage in Java

荒凉一梦 提交于 2019-12-02 06:22:06
Does anyone know how to print a BufferedImage in Java? Printing is just like drawing on the screen, so eventually you get a Graphics object, and you just drawImage into it. nsfyn55 I'm not sure what you mean by print. Print on a printer? Print to standard out? Write to a file? You can check out this tutorial from sun. If you're looking to write to a file. Open in your favorite image tool and print from there. http://download.oracle.com/javase/tutorial/2d/images/saveimage.html If you're building a graphical app and using something like AWT you can using the java printing API which would