javax.imageio

Java BufferedImage saves with unwanted background color

时光怂恿深爱的人放手 提交于 2019-12-05 06:43:17
Thanks ahead of time for the help Description: The program draws, displays, and saves an image. It works as following: the object itself extends Frame. In the constructor, the object creates a BufferedImage, and calls a method that draw onto that image. Then, it displays the image onto the Frame. Finally, it saves the image into a file (I don't care what format it uses). The main program creates the object, which does the rest. Problem: The saved file always has a colored background! This is especially wierd since the displayed image is fine. If I use "jpg" format with ImageIO.write(), the

save resized image java

和自甴很熟 提交于 2019-12-04 22:56:47
问题 How do i save a resized image to a specific folder? private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { ImgChooser ic = new ImgChooser(); ImageIcon icon = new ImageIcon(me,"id pic"); Image img1 = icon.getImage(); Image img2 = img1.getScaledInstance(105, 105, 0); icon.setImage(img2); jLabel1.setIcon(icon); } This first code is where i get the image and resize it. Then i want the resized image to be saved in another folder. Thanks in advance 回答1: Use ImageIO.write(...) as

iOS4 calling ImageNamed: still leak or cause memory issue?

空扰寡人 提交于 2019-12-04 19:57:08
So apparently, my app crashes on ipod 2nd generation due to low memory issue. What I do was calling image on each view within scrollView + pageControl when user scrolls. And app crashed when it reached a particular point after got memory warning. I tried to free up view when I got warning but it still caused crash. I googled about ImageNamed: and apparently there was issue within this api call, but most article said it was fixed in recent iOS version. I fixed this problem with calling image imageWithContentOfFile instead imageNamed, but I'm wondering if ImageNamed still causes memory leak or

Creating a jpeg file with metadata

流过昼夜 提交于 2019-12-04 19:07:08
I have a Java application that creates a BufferedImage and saves it to disk as a JPEG. I'd really like to add a caption to the image. To prevent the image from getting crowded out by text on the image itself, it'd be great if I could write the caption to the JPEG's metadata. I've been searching all over the place for a solution, but haven't found anything satisfactory. Sanselan comes up a lot, but I haven't figured out how to use it properly. I found examples that modify existing metadata, but my files don't contain metadata as they are simply created from ImageIO.write() or Sanselan

Write tiled output of TIFF, using ImageIO in Java

爱⌒轻易说出口 提交于 2019-12-04 14:13:07
What I have is a a large number of frames that need to be placed together in a larger image (like a mosaic). The required positions of the images are known. There are a very large number of images so loading them all into memory is impractical at best. Based on some other answers here I was able to override the methods in RenderedImage (specifically getData(rect) ) to load in the appropriate data and return it. This works just fine, however the image writer is always calling getData and requesting rows of data. It seems to me I should be able to change the ImageWriterParam to call for

Java ImageIO is insanely slow

自闭症网瘾萝莉.ら 提交于 2019-12-04 12:36:08
I'm making a program that sends the clients screen to the server and displays it but it's being extremely slow. It's taking 2-3 seconds for one frame and the upload/download speed is not a problem. Is there anything I'm doing wrong/anything I can change to speed this up? Server: import java.awt.BorderLayout; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.util.zip.GZIPInputStream; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing

Unable to acquire image through ImageIO.read(url) because of connection timed out

喜你入骨 提交于 2019-12-04 07:45:00
The following code always seems to fail: URL url = new URL("http://userserve-ak.last.fm/serve/126/8636005.jpg"); Image img = ImageIO.read(url); System.out.println(img); I've checked the url, and it is a valid jpg image. The error I get is: Exception in thread "main" javax.imageio.IIOException: Can't get input stream from URL! at javax.imageio.ImageIO.read(ImageIO.java:1385) at maestro.Main2.main(Main2.java:25) Caused by: java.net.ConnectException: Connection timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl

How to resize an image without loading into memory?

不打扰是莪最后的温柔 提交于 2019-12-04 07:04:35
I'd like to check the dimensions of an image, and then size it down if the width exceeds a given threshold. When I load a 6MB JPEG image with ImageIO.read(), the BufferedImage allocates about 45MB of heap space. Is there a way to do a passthrough image resize without loading all the data into memory? I tried passing ImageIO.read() a File object, thinking it would stream the data from disk, but it doesn't help. Check out im4java and JMagick . Both use an extremely efficient external tool called ImageMagick for image manipulation. Im4Java calls the command-line app (does work in separate process

Javax ImageIO IIOException for apparently no reason

前提是你 提交于 2019-12-04 05:43:38
问题 Hey all, I have a Java problem. For my senior research class, I'm pretty much finished but I just have to analyze some data in images I generated. I don't want to tag this as homework because it's not part of any required assignment...it's something I came up with on my own to collect results. I wrote a program that compares two images pixel by pixel. It does this for all .bmp files in two directories. Now, my program reads the filenames into a String array and I checked the values of all the

How to make ImageIO read from InputStream :Java

强颜欢笑 提交于 2019-12-04 05:24:24
I have created executable jar file(using Eclipse) , there are a set of image (.png) files that is to be inculded in the jar. So I have added a source folder with all the images inside /images folder in the project . Code has to access these file to create BufferedImage using ImageIO.read(new File(path); Earlier, To get the path I used ClassName.class.getResource(/image/test.png).toURI(); On executing jar , it throw error URI is not hierarchical So now I am using ClassName.class.getResourceAsStream(/image/test.png); But how to make ImageIO read from Inputstream ? I tried cast as follows