BufferedImage to array - java

What are the advantages of converting a buffered image into an array of integers?I assume that i can manipulate the array and cross process the picture .Is that so?

I think you are referring to getRgb() method of BufferedImage class.
Supposing you want to modify the whole image or a big portion of it, retrieving the pixel array, and perform operations on it could be considerely faster than accessing each single pixel through method calls such as setRgb().

SwingX introduces the AbstractFilter class for BufferedImage. Here is an example:
http://www.jarvana.com/jarvana/view/org/swinglabs/swingx/0.9/swingx-0.9-sources.jar!/org/jdesktop/swingx/image/GaussianBlurFilter.java?format=ok
For simple editing use one of this examples:
http://www.exampledepot.com/egs/java.awt.image/imagepixel.html
Buffered image pixel manipulation
How do I create a BufferedImage from array containing pixels?

Having a BufferedImage into memory as an array of int values could help you apply filters on the image by processing the int values into memory and then setting the result back to another BufferedImage.

Related

Suitable file type for combined raster and superimposed geometric data?

I am creating a java application in which you can trace the composition of a photo or image by drawing lines or shapes over the image, e.g. drawing the horizon line/ vanishing point/parallel lines/outlines. Thus you get a data set in addition to the raster data which you can analyse and compare to other images, e.g. by comparing line equations.
My question is: What would we a suitable file type to contain both the raster (rgb+alpha) data of the image and the geometric data of the traced-over composition lines?
You might consider making a custom class whose members are the image you're describing and a list of the appropriate geometric primitives, e.g.:
class GeometricImage {
public BufferedImage image;
public List<Line2D> lines;
}
And then, assuming you don't require interoperability with non-Java applications, you can simply use Java's serialization facilities to write or read the instances from or to a file.

Serializing/Deserializing buffered images

I have a collection of buffered images that I want to serialize and then deserialize.
For example I have an arrayList full of buffered images which are iterated through and written to a
ObjectOutputStream
for (BufferedImages i : images{
ImageIO.write(i,"png",ImageIO.createImageOutputStream(output));
}
When I go to re-serialize the images, I tried to use
BufferedImage image =ImageIO.read(ImageIO.createImageInputStream(input));
but it only reads in one image.
Whats the correct way to re-serialize a collection of buffered images stored within the same serialized file?
Also once the images have been re-serialized they get redrawn to a JLabel,
How do I know which image is the correct one for each JLabel?
Edit:Problem solved
Ended up converting the buffered images to a byte array then stuck them in a hash map and used some hash codes as keys.
Then serialized the hash map.
All good.

Android image strip and edit / combine 2 pictures

I want to create an android app that takes 2 pictures (taken from the phone camera). Takes the top part of pic1 and the bottom part of pic2 and combines them to the final picture.
I'm thinking about converting each image to byte array. Then take the half values from the array of the first image and the other half from the other image, merge them in the final array and convert that array back to image. Is it feasible? Is this a good solution or there is any better practice for this?
Well I guess I found the solution. There is a class in the Java6 API called "BufferedImage". This class has the methods: setRGB , getRGB where you can get the int value of the rgb color for the pixel you specify. This way you can get the pixel color from the image you want and set it in the target image.
Try using OpenCV. It will be very fast since it will be handling the images in native code. Convert Bitmap objects into Matrix(OpenCV) object and send the address to the native code where you can do these computations very easily. If any code is required, do let me know.

Combining several images in Java

I have these several images which I need to be combined using BufferedImage in java. The logic of the program is this:
The user will be asked to input data (5 times) then the inputted value will be generated to image (I'm done coding with this part). My problem is how can I Combine them into one image only. Thanks!
You can create another new image. Depending on how you would like to combine the images you have two possibilities:
Call getGraphics() on the newly create BufferedImage and use drawImage() multiple times to draw your other images into the newly created one (for example to create a tiled image with all the images you create beforehand)
Call getRaster() on the newly create BufferedImage and use the methods of this object to draw information from your other images into this image (this way you can achieve any blend effects you might need)

Efficient way to draw into a java.awt.graphics object

I'm trying to create an animation by dynamically generating frames at each step of the animation. Now as I need to run an algorithm to draw pixel by pixel the new frame and I'm using a BufferedImage that I access through its raster data.
However 90% of the time is spent inside java.awt.graphcis.drawImage() that I use to transfer the image into the content of a JFrame.
Is there a more efficient way to draw pixel by pixel inside a graphics object?
Try to use VolatileImage. Much faster than that is hard to do..

Categories

Resources