JavaFX - painting a rgb array as an image - java

We are using vlcj to capture a webcam video and display it on the user screen. We capture it frame by frame, a 1280x720 image at around 30fps.
Our app UI is entirely JavaFX, and we are having problems displaying said frame.
Using Swing, we would do something like:
BufferedImage image; //create compatible image
public void onDisplay(int[] rgbBuffer){
image.setRGB(0,0,width, height, rgbBuffer, 0, width);
myJPane.repaint();
}
But JavaFX's Image class offers no such methods, and creating a BufferedImage just to convert it to a JavaFX Image (by using Image.impl_fromPlatformImage()) is highly costly.
Question: How does one create a JavaFX Image, that can be set to an ImageView, based on a rgb int[]? Is there a better (as in "faster") way to display it?

This functionality is not yet part of the JavaFX platform - for now I believe you have to use the BufferedImage method you are currently using.
You can track the feature Image Ops request. Anybody can sign up for a jira account and vote for the issue/add comments/detail use cases/etc or provide input to the design on the JavaFX development mailing list.

Related

Get a BufferedImage output composed of several image layers

for my current work, I need to add images on top of other images at runtime. I already searched and I don't want to draw it on a Swing component, I use it in an external API.
Ideally, I would like a library (or a java-native way) with which I can specify several images to "layer", and it would return me a BufferedImage (or any Image object by the way).
If you want a single image (BufferedImage) in return, then you need to compose your images.
This answer may help you stackoverflow.com/questions/2318020/merging-two-images.
Have a look at the documentation for method drawImage to control position and scaling of any drawing through the Graphics object.

How to quickly show a rendered image in Swing?

I have an image saved as byte array, which is already rendered and will fit perfectly into my GUI application (no filtering, rotation, resizing or color transformation is needed). What is the fastest way to show the image?
I'm not sure what Swing is doing internally with the image before it actually shows it. But I try to bypass all these steps and directly show it without any additional Swing processing. Can you think of a way to do this?

Copying a snapshot of a Canvas to a BufferedImage

I'm currently using a Canvas with an associated BufferStrategy. How can I copy the contents (image) of the Canvas and save it to a BufferedImage. So far I've only tried
BufferedImage image = ...
g = image.createGraphics();
canvas.printAll(g); //or paintAll
However, it appears that only a 'blank' (filled with the background color) screen is being drawn; I it's assume because that's the default behavior of Canvas.paint(). Is there as way for me to retrieve the image currently on screen (the last one shown with BufferStrategy.show()), or do I need to draw to a BufferedImage and copy the image to the BufferStrategy's graphics. It seems like that would/could be a big slow down; would it?
Why (because I know someone wants to ask): I already have a set of classes set up as a framework, using Canvas, for building games that can benefit from rapidly refreshing screens, and I'm looking to make an addon framework to have one of these canvases tied into a remote server, sending it's displayed image to other connected clients. (Along the lines of remotely hosting a game.) I'm sure there are better ways to do this in given particular cases (e.g. why does the server need to display the game at all?) But I've already put in a lot of work and am wondering if this method is salvageable without modifying (to much of) the underlying Game framework code I already have.

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.

swing offscreen rendering with simulated input

I am trying to do render a swing UI into an OpenGl texture. All that works so far is this piece of code (btw it is Scala, but it should be obvious)
var image = new BufferedImage( width, height, BufferedImage.TYPE_4BYTE_ABGR)
mainFrame.paint(image.getGraphics)
var outputfile = new File("saved.png")
ImageIO.write(image, "png", outputfile)
But those things are still missisg:
I need to be notified when anything in the swing components changes, so that I can update the glTextures when needed.
The rendering to a swing window should be disabled
A virtual mouse would be nice, so that I can use my projected mouse position on the texture
Dynamic keyboard processing, so that I can activate keyboard processing as long as the UI is active. Else I would use LWJGL input processing.
I think the best way to approach the first two issues would be a Decorator to the Graphics object used to draw all the swing components, but I did not find any way to implant my variation of that class into Swing.
I hope that's it. But if you know a library that has already solved my problem you are welcome, but please do not recommend TWL.

Categories

Resources