Create an image from a Swing-GUI - java

Is it possible to create an image from an existing Swing-GUI programmatically?
What I want is, that the GUI can be printed out, therefore I need an Image, as the printer only takes images to print...
Looking forward to your answers!

Take a look at Screen Image. You can make an image of any component.

Related

Are there any ways to modify a JavaFX Image Object?

I'm showing an Image on a Canvas using JavaFX, but I would like the color of certain parts of the image to vary based on a variable. Ordinarily, I imagine this would be accomplished by creating a color mask and adding that to the image, but as far as I can find JavaFX Image doesn't allow any operations like that, and from the documentation it looks like JavaFX Images can only be loaded from a file. I don't want to modify and then reload the file each time the color changes, because that seems pretty inefficient performance-wise.
My goal is to create an interactive offline app in which a small character is shown, and the user can (for example) use an input to change the characters eye/hair color.
Are there any ways to accomplish this? Essentially doing basic image masking/coloration with JavaFX Images and canvases. (Not ImageView)
Thanks for any advice you can give me!

Scale text size on Canvas

I'm usint this class that provide to draw a cicle with inside a title and subtitle. the code is this (i'm not the author): https://github.com/ylyc/circular_progress_bar/blob/master/src/com/lylc/widget/circularprogressbar/example/CircularProgressBar.java . All works fine but when the subtitle text is more large it outside of the parent.. how can i scale this programmatically according to the screen resolutions? Thanks.
check this out
http://docs.oracle.com/javase/1.5.0/docs/api/
it has all of the methods in java in it. just look up the class of the object for the text and see if there is one.

Create "invisible" graphics

I need Your help in generating offscreen images from graphics class and converting them to binary data without setting them visible on screen.
I want to generate large amounts of labels and send them to a printer as binary data. If i create the image, show it on screen and then send it, everything is ok, but i generate 100 labels in one minute and it is annoying when they flicker on the screen of my java aplication.
I want it to be generated by a seperate thread, without visible efects.
If i don't show them, the labels are send black. I tried to generate them, and then show them off screen, that did not match my expectations.
Is there a way to generate "invisible" images from Graphics2d??
or
Is there another way You could suggest me?
Thank You in advance
Qba
You can use a BufferedImage and use getGraphics() to get hold of a Graphics2D object that paints onto this image.
If you're after painting GUI components (if your "label" refers to JLabel for instance) you could have a look at these questions:
How to get a BufferedImage from a Component in java?
Java/Swing offscreen rendering (Cobra HTMLPanel -> BufferedImage) Problem: Component doesn't finish redrawing first

Creating a color image in j2me

I need to create different image size with green color in microedition, is it possible?
I need to create the image on the fly without loading an image.
Here you go,
http://www.java2s.com/Code/Java/2D-Graphics-GUI/DrawanImageandsavetopng.htm
change the color from black to green in example.
If you want images to be unique draw unique numbers instead of text.
if you don't want to use text in the image then simply draw something but start the drawing at a random location in the image.
Out of curiosity are you trying to test the servlet or the phone app?
Sorry earlier I missed that you wanted to achieve this in J2ME
See the link below
http://www.java2s.com/Code/Java/J2ME/MutableImageExample.htm

How to create a custom Java Swing GUI Component with a shape and gradient

I have to create a custom component on my JFrame, the Component will show the storage status of that user, the storage will be in percentage.
I need to create something like this:
I tried a custom JLabel to create a label and then coloring that label from left to right, but I was unable to create a cloud shape Label and then filling that label according to a variable value.
How should I do this and what is the best way to do it?
One time I thought I should use series of images to show the status of user storage.
Thanks!
I think you're going to need to use an image mask (examples here and here) if you are to replicate that cloud exactly.
The process will require 2 images:
The cloud outline (the blue parts)
An image mask is the shape of the cloud, probably black outside and white inside
Then your drawing process, which you'll have to do each time the % storage changes will be:
Create a new buffered image
Draw then green fill bar in the style you want (e.g. slanted as in this image)
Copy the image mask over this
Draw this new image to the screen, with the mask applied as described here
Draw the cloud outline image to screen
That's going to take an hour or so for you to put together, so I'm not going to do it for you. Have a go, and if you run in to problems (or don't understand anything I just described) then ask about that specifically.
You can use GlyphVector#getGlyphOutline() to get the shape of a Unicode character like ☁ \u2601 and fill it with a GradientPaint.
You can do that with a JLabel and a custom-implemented class derived from Icon.
doesn't this help? Java gradient label example
And if you understand (or can translate from) portuguese, there's also this discussion with a solution at the end

Categories

Resources