How to use Java and NetBeans to display data as an image - java

I am new to Java and NetBeans but have experience in C/C++. I will be working on an application which will have an area to display an image. The image will be created in memory as an array of unsigned bytes and considered to be monochrome.
I'm looking for a tutorial or examples of displaying data like this as an image. (The data will be read from an imaging radiometer - every few seconds) I've looked at some classes in AWT but I need an example.
Thanks

Have a look at Trail: 2D Graphics and BufferedImage.

Here's a very simple example of manipulating the pixels of an off-screen image directly. This more complex example examines several approaches to accumulating image data in a separate thread and viewing periodic updates.

It looks like you have two problems.
Creating a java Image object from an array:
Turn an array of pixels into an Image object with Java's ImageIO?
Displaying the java Image:
How to add an image to a JPanel?
More info on rendering with a JPanel can be found here:
http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html

Related

How does warpPerspective in OpenCV works

I have recently started exploring OpenCV and I am having trouble to understand warpPerspective, documentation does not help much. I mean why is it used? And if I need to resize an image, I can use resize method, then what additional benefit will i get using warpPerspective method.
To make it simple, warpPerspective allows you to create a new image from a transformation matrix.
It is much more powerful than a resizing function.
Simple summary :
Example with a very popular application
You have picture 2 above and want to extract the document (result in picture 3).
Get the template of it (picture 1) and compute the homography (transformation matrix between picture 1 and picture 2).
Using this transformation, you will be able to create image number 3 using the transformation matrix in warpPerspective.
Example from an article from learnOpenCV written by Satya Mallick

Manipulating Pixels(Drawing) in Java

This is not a typical "what library do i use?" or "is there an API for that". Using lines of code I create not implementing them through a library of sorts. Is there any documentation on how to actually create a window, and within that window draw a line from pixels?
I just want to understand how its done, and not learn through a library which does it for me.
Previously tried:
JavaFx
Swing
If you want to draw a line in a window, you'll ultimately have to create a BufferedImage, set pixels in that BufferedImage according to some drawing algorithm (like Bresenham's), then put the BufferedImage in the window.

Java Drawing shapes to file of 2D object

I have a play framework application which I want to be able to produce a product label from. I have the label design in illustrator. It consists of a black circle, white writing with a QR code in the middle, also has curved text.
I want to create a high resolution PDF and/or image file of this design on the fly. All most all of the drawing stuff I find for java relates to swing.
Anyone done this?
The basic class which allows creating an image programatically is BufferedImage and the corresponding Graphics2D class. You are not forced to use it with Swing. You can easily convert it to common graphic formats like PNG. Then you can save it as an image file or place it in a generated(e.g. with iText) PDF.
http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics2D.html
In other words - yes, it can be done.
But if I ware you I would consider exporting the design from Illustrator to a file and use it as a resource in your application. But if you need to scale it programatically you ought to consider using SVG format to avoid loosing quality. Java does not have build-in support for vector images so you should look at
Apache Batik

Is it possible to store constructed images for display later using Java Swing?

I am a C/C++ programmer trying my hand at Java for the first time. I'm currently working on a program that reads in a bunch of data and builds a map. I want to give the user the option to toggle various features of the map using check boxes.
In the Win32 API, I was able to accomplish this by pre-building the features on transparent bitmaps and then BitBlt()ing them over top one another. Does Java Swing support something similar? I imagine I'm not the only person who has ever wanted to do this. Building the features is relatively slow, so I only want to generate the layers once and then block copy them to the JPanel I'm using as a display.
Thanks in advance!
You could dynamically create BufferedImage objects, with alpha channels, then only paint this on a frame if the checkbox is checked.
You can store images in Swing using the BufferedImage class, and then use that to later draw the final image.
http://docs.oracle.com/javase/6/docs/api/java/awt/image/BufferedImage.html
The final image can later be painted on to the JPanel (probably by overriding the JPanel's paintComponent method) by using the alpha values of the images.

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)

Categories

Resources