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
Related
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);
I am loading an external image with JavaFX:
Image tile = new Image(imageFile.toURI().toURL().toString(),width, height, true,true);
You need to supply the width and height. How can I get the image's width and height?
Now, I know that the width and height of a PNG image are determined by the bytes from 12 to 20 or something like that, so technically you could open a byte stream and interpret the bytes. However, this seems overkill for the simple task of drawing an image in my JavaFX application. Is there not a way to draw an image with its full size without asking me to supply the dimensions?
Just create the Image using a constructor which does not include dimensions (e.g. new Image(url)):
Image image = new Image(url);
So I have no clue why this is happening. I am using Universal Image Loader to load these images. It seems like the last line of pixels is being streched for some weird reason. I want the image to just stretch out evenly. (I don't care that it will look weird. The images below are for demo purposes.)
Also, don't mind the first and last image. I purposely blurred that out because it had someone's face on it.
This is how I set up my Universal Image Loader:
//setup Image Loader for loading cruise line logos
displayImageOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_launcher)//show this image when image is loading
.showImageForEmptyUri(R.drawable.ic_launcher)//show this image incase image doesn't exist
.showImageOnFail(R.drawable.ic_launcher)//show this image if fetching image from URL didn't work
.cacheInMemory(true)//cache image in RAM
.cacheOnDisc(true)//cache image in device for later use
.considerExifParams(true)
.displayer(new RoundedBitmapDisplayer(5))//super subtle rounded corners on images
.build();
This is caused by the way RoundedBitmapDisplayer draws the bitmap.
If you look at the source, you'll see that it uses a RoundedDrawable, which uses canvas.drawRoundRect() to draw a rounded rectangle of the desired size of the Drawable, using the downloaded image as the texture via a BitmapShader. BitmapShader does not support scaling (only clamping and tile modes). Try using a SimpleBitmapDisplayer instead which uses the normal ImageView.setImageBitmap() way of displaying the image.
If you need rounded corners, you'll have to find a different way to implement that, for example by scaling the Bitmap to the desired size first. Another option is to call Canvas.saveLayer() before delegating to BitmapDrawable for the scaling, and then applying the rounded corner masking effect using PorterDuff.Mode.DST_IN. Either way you'll end up writing a bit more low-level code, but you should be able to encapsulate everything nicely in a custom BitmapDisplayer.
I am trying to rotate a GIF image in java.
I read these interresting two trails about rotating images in java : trail 1 , trail 2.
All works fine, except that when I rotate my GIF image, there is no more animation of the GIF image. Only the first image of the GIF animation is displayed.
So, is there any way to keep the GIF animation after rotating my GIF image, without using any third part library but only standard J2SE?
Or will I be obliged to separate my GIF image into single images, rotate them one by one, and then display them in a loop?
I don't give any piece of code I wrote because it is not relevant in my humble opinion.
I think animated gifs work by storing multiple frames, all in the gif format.
So you just need to apply you rotation method to every single image, instead of the whole gif.
Wikipedia has a quite nice description of the format
Please answer these questions:
Is it true that if a BufferedImage is of type INT_ARGB it will be rendered at the same speed as a Toolkit generated Image object?
Are BufferedImages and Images "equal" for games? (speed & memory efficiency wise)
Is it correct that BufferedImages will not play an animated *.gif because the image data is buffered?
Will the animated image data stored in an Image object be lost if the Image is drawn to a BufferedImage which is then rendered to the screen through a Graphics object?
While BufferedImage is not intrinsically animated, they are frequently used to pre-load or pre-render complex images in order to speed up animation. This KineticModel is an example. This AnimationTest shows one way to examine rendering time.