I was wondering how you can switch the picture being loaded into a buffered image when an action is called?
For example, if the buffered image is currently loading "Hand.png", I want to be able to press a button or a key, and have it load "Foot.png" instead. My action listeners and buffered image are set up correctly, I'm just unsure of the syntax required to change a BufferedImage.
don't change the image, create several images and display different images depending on events/actions
Related
I need to set an image inside the square box under the hanger, what is the best technique to set the new image over this background to exactly fit inside the box in case of small or large screen devices.
I have got an image in my javafx software and I want to define its size from my code. The code where with which I am reading the pic is the following:
image= new Image(gui.getClass().getResourceAsStream("img.gif"));
imageIMG.setGraphic(new ImageView(image));
I want to define the size of this image in my GUI. When I am trying to setup the size I found out that I cannot use a method like image.setHeight/Width. Why I cannot define the size of the image? Is there any alternative way to do so?
EDIT: This is what I am performing to load the image in my graphics.
An Image in JavaFX is only a container for the image data. You can scale the image at loading time (using another constructor) but this change is permanent (but can be useful to save memory).
When you want to display an Image, you wrap it in an ImageView. This class has methods to scale the image dynamically, depending on where you need it. It won't change the underlying data.
Image can be re-used. You can use the same Image in multiple ImageViews and show it at different sizes without having to have multiple copies of the same image loaded.
Update
image= new Image(gui.getClass().getResourceAsStream("img.gif"));
ImageView iv = new ImageView(image);
iv.setFitWidth(100); // Change size
imageIMG.setGraphic(iv);
ImageIcon v = new ImageIcon(getClass().getResource("/Sample1/Image1.gif"));
v.getImage().flush();
jLabel1.setIcon(v);
JLabel2.setText("Sample");
How to finish the animation first before changing the text of jLabel2?
Assuming that Image1.gif is an animated GIF, I see two approaches:
Extract the images from the GIF, as shown here, and display them in a single sequence.
Play the GIF for a fixed period, then set the label's icon to one constructed from a BufferedImage copy of the GIF, as shown here.
In either case use javax.Swing.Timer as required for timing
I'm wondering if it's possible to combine more than 1 image into a gif?
So, essentially you import 2 photos and make a gif out of them.
Thanks.
Certainly, here is a way to do this:
Create the final image as a new BufferedImage(...)
get a Graphics object on the image with image.getGraphics()
call graphics.drawImage() for each image you want to put on the larger image (you can load these images with ImageIO)
use ImageIO to write the BufferedImage out as a GIF
I'm wondering..
1)is it possible to set an imageview's resource to the URL location of an image?
2)is there a way of setting the x,y co-ords of where on the screen to draw the imageview?
3)How would I run a check to see if the space is taken up by another Imageview (must specifically be an imageview)
4) How would I make the Imageview "clickable" e.g if the user clicks the image it'll do something?
5) How would I dynamically create imageviews? E.g if a condition is true make another imageview
Perhaps I'm going about this wrong so I'll explain better what I'm looking to do.. basically I want to draw images on the screen which are located at URL's. I want to display N amount of images (There will be conditions which will decide how many images I'm displaying, so it'll have to be dynamically created) each image should take up approx 50x50 screen space. There will be other conditions to where the image should be displayed.. If an image exists at a certain co-ord it shouldn't draw over it, when the user clicks the image something else should happen.
Hopefully this makes things clearer.
Thanks.
Not directly. You can download image afer program was started, then convert it to Drawable and display on screen. But you cannot assume user always enables data transfer, so often image won't be downloaded at all.
Yes, but much better is to use Layouts - different handsets have different screen resolutions and desinty.
No simple answer - it depends, how you prepare and display screen contents.
((ImageView)view.findViewById(R.id.imageid)).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//something
}
});
It sounds like you don't need ImageView (the graphics component used to place image in various layouts) itself, but rather some kind of canvas. Anyway, see:
How to add 3 images in a canvas in android
Drawing to the canvas