bufferedimage

BufferedImage leaks - are there any alternatives?

折月煮酒 提交于 2019-12-04 15:52:46
I am having strange problems with BufferedImage, which in some cases consumes all the free system memory (3GB, 1.5GB free). I have created a simple wrapper and I use it like this: public ImageWrapper(final byte[] bytes) throws ImageWrapperException { this(new ByteArrayInputStream(bytes)); } public ImageWrapper(final ByteArrayInputStream bis) throws ImageWrapperException { try { image = ImageIO.read(bis); bis.close(); } catch (IOException e) { throw new ImageWrapperException(e); } } (I have jsut verified that it happens even with image = ImageIO.read(file); ) I am not getting any exceptions

How to bend an Image in java

一曲冷凌霜 提交于 2019-12-04 15:04:16
Is there any way to bend a BufferedImage in Java? I thought that if I crop the image into smaller pieces and rotate them then I would essentially bend the image, but it doesn't seem to work. Here is the method I created: /** * This is a recursive method that will accept an image the point where the bending will start and the point where the bending will end, as well as the angle of bending * * @param original:the original image * @param startingPoint: the point where the bending should start * @param endingPoint: the point where the bending should end * @param radiands: the angle * @return the

java.lang.OutOfMemoryError: Java heap space when stitching 13k .png images together

谁说我不能喝 提交于 2019-12-04 14:28:19
I have 13255 images, each 240 x 240 pixels wide, the biggest 15,412 bytes in size and the smallest 839 bytes. I am trying to loop through the folder adding each of them to a File[]. Once I have an array of each image I am then placing them inside a BufferedImage[] ready to be looped through and drawn onto a larger single image made up of each individual one. Each image is named in the form of Image x-y.png However, I keep ending up with a java.lang.OutOfMemoryError: Java heap space error. I have no idea why. I have tried altering the size of the memory available to the JVM by adding parameters

Android alternative to java.awt (BufferedImage and Raster)

99封情书 提交于 2019-12-04 12:03:54
问题 for my final year project I am developing an android app that can capture the image of a leaf and identify what type of tree it came from. I have a nearly completed PC version (developed in java) and i am starting the process of porting it to android. Although BufferedImage and Raster make up a key part of my program, this is a problem because java.awt is missing in android, so this means i have to alter the library. I am using a library that was developed by my lecturer, the method below

Why does a BufferedImage require so much memory beyond the size of its data array?

强颜欢笑 提交于 2019-12-04 10:15:55
I'm trying to determine how much heap any given TYPE_INT_ARGB BufferedImage will use so that, for a program which is doing some image processing, I can set a reasonable max heap based on the size of image we feed it. I wrote the following program as a test, which I then used to determine the least maximum heap under which it would run without an OutOfMemoryError : import java.awt.image.BufferedImage; public class Test { public static void main(String[] args) { final int w = Integer.parseInt(args[0]); final int h = Integer.parseInt(args[1]); final BufferedImage img = new BufferedImage(w, h,

What is the fastest way to draw pixels in Java

*爱你&永不变心* 提交于 2019-12-04 08:12:36
问题 I have some code that generates particles at random locations, and moving in random directions and speed. Each iteration through a loop, I move all the particles, and call repaint on my jpanel. For 1,000 particles, I'm getting around 20 to 30 frames per second. I plan to eventually have 100,000 to 1,000,000 particles. In paint, I only create a new bufferedimage if the window has changed size. I draw the pixels to the bufferedimage, and then call drawImage to display the image. Each particle

Write back modified image from imageReader

≡放荡痞女 提交于 2019-12-04 05:19:49
问题 I read separated images from animated gif and I need just make change with them in frames[i] and then set them back to file and save with writer as new file. File file = new File("gif1.gif"); ImageReader reader = ImageIO.getImageReadersBySuffix("GIF").next(); ImageInputStream in = ImageIO.createImageInputStream(file); reader.setInput(in); File output = new File("k.gif"); ImageWriter writer = ImageIO.getImageWritersBySuffix("GIF").next(); ImageOutputStream out = ImageIO.createImageOutputStream

Convert OpenCV Mat object to BufferedImage

拥有回忆 提交于 2019-12-04 04:42:45
I am trying to create a helper function using OpenCV Java API that would process an input image and return the output byte array. The input image is a jpg file saved in the computer. The input and output image are displayed in the Java UI using Swing. System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // Load image from file Mat rgba = Highgui.imread(filePath); Imgproc.cvtColor(rgba, rgba, Imgproc.COLOR_RGB2GRAY, 0); // Convert back to byte[] and return byte[] return_buff = new byte[(int) (rgba.total() * rgba.channels())]; rgba.get(0, 0, return_buff); return return_buff; When the return_buff is

Jcrop not cropping properly the images

匆匆过客 提交于 2019-12-04 04:24:29
My jcrop code $(function(){ // Create variables (in this scope) to hold the API and image size var jcrop_api, boundx, boundy, // Grab some information about the preview pane $preview = $('#preview-pane'), $pcnt = $('#preview-pane .preview-container'), $pimg = $('#preview-pane .preview-container img'), xsize = $pcnt.width(), ysize = $pcnt.height(); //console.log('init',[xsize,ysize]); $('#target').Jcrop({ onChange: updateInfo, onSelect: updateInfo, onRelease: clearInfo, setSelect: [0, 0, 150, 180], boxWidth: 400, boxHeight: 300, allowMove: true, allowResize: true, allowSelect: true, aspectRatio

BufferedImage unexpectedly changing color

与世无争的帅哥 提交于 2019-12-04 01:34:49
问题 I have following code, which creates grayscale BufferedImage and then sets random colors of each pixel. import java.awt.image.BufferedImage; public class Main { public static void main(String[] args) { BufferedImage right = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_GRAY); int correct = 0, error = 0; for (int i = 0; i < right.getWidth(); i++) { for (int j = 0; j < right.getHeight(); j++) { int average = (int) (Math.random() * 255); int color = (0xff << 24) | (average << 16) |