How to merge two GIFs in Java? - java

I have to GIFs with the same size. One in animated and transparent, the other one is only plaintext. How can I merge both so that the animated one is on top and I can see the text tru the transparent parts and I only have to display one GIF in my app?!
Cheers

'Layers' is what first comes to mind and what seems to be the solution in this related question:
Image handling in Java

Related

Using multiple backgrounds in Android Application

Here is a scenario on which i done a lot of research on google but hopeless. the scenario is, i am going to develop a 2D game in which i want to use multiple backgrounds and i want to translate them as they are moving forward, it must look like one background is near and translating/moving fast and the other background is a bit far and translating/moving a little slow. the nearer background have almost full intensity and the farer background have a bit low intensity. you can say they have different transparency levels. the question is, how can i get this task done or is this possible to use multiple backgrounds.
any suggestion will be appreciated.
as an example, see the image of BADLAND game bellow.
I think as far as I got your question you want to put two or more images one over another. I mean if you are trying to overlap the multiple backgrounds and asking for it yes it can be done easily.
What you need to do is to use the FrameLayout. as
"FrameLayout represents a simple layout for the user interface of
Android applications. It is usually used for displaying single Views
at a specific area on the screen or overlapping its child views."
and then you can implements the animations on them and translate them You can find different types of translation over them.
Here is all about using the frame layout frameLayout1 framelayout2 and for animations and translation here are links. link , link2 , link3

Put text on animated GIF and save it as a new GIF

I'm looking for a function that could process animated gif image to write text on top of it.
The working solution is probably provided by Gif4j lib, but I'm looking for open-source solution or advice how to implement it on my own.
How can I put text on a gif and save it as a new gif in Java?
You need to:
Split the animation into separate frames.
Write the text on each frame. For examples see answers like these (the first is more closely related, but the second source does the same, and is simpler).
Java Text on Image
How to resize text 1
Construct the frames into a new animated GIF. See Create animated GIF using imageio at the OTN, where I discuss the code used in a GIF animation tool.

Java: get frames from animated GIF without ImageReader

I'm developing AppEngine application. One of it's features is splitting an animated .gif image into separate frames. I've searched a lot to find the way how to do it and finally found the solution. Unfortunately the solution is based on ImageReader and I cant use it on the server, because:
javax.imageio.ImageReader is not supported by Google App Engine's Java
runtime environment
Are there any other ways to decode GIF-image without this class?
First some thing about frame itself. There are two implications about splitting an animated .gif image into separate frames. 1) Literally, a frame is a frame in the sense of an animated GIF. The problem is frames which constitute an animated GIF image are related. The disposal method of an animated GIF dictates what to do with the previous frame when drawing the current frame. You can override it; fill with background color before drawing the new frame, or you can do whatever you think appropriate before drawing the new frame. If you think the above situation is complicated, what about transparency of frames? logical position to draw each frames?
If we go along this road, there is no need to use a dedicated ImageReader, just read relevant parts of the image and copy each frame data, save it along with a header and color palette. The consequence is: the resulting image might look weird and meaningless. Look at the example below:
The first frame
The second frame
And the original
You can see the second frame doesn't look so good. The truth is, the second frame is a transparent one which build on top of the first frame (this animated GIF only contains 2 frames). You are expect to see through the second frame and altogether, they make an animation.
Now let's see what the second implication of splitting an animated .gif image into separate frames. 2) In this case, the frame is a actually is a composite which builds upon the previous frames and which is what we are seeing when viewing an animated GIF. In order to achieve this, we have to take into effect the history of the frame loop, the logical position of each frame, and the transparency of the frames themselves.
Let's see what we get now:
The first frame
The second frame
Now the first frame is the same as in the first situation, but the second frame is constructed on top of the first one and it's not transparent anymore.
In the second case, we do have to decode and encode the frames to achieve the desired result. Besides looking nice, another good thing about this is you can save the resulting images in any format the encoder support.
The examples in this post are generated by the GIF related part of iCafe

java android - fit items on a image background with different screen size

This is my first post and i have (i think) a uncommon request...
I'm programming on the last Eclipse Mac, for every android SDK, and i'm using more XML for layout than runtime... So i search a solution in XML if possible.
Here is the situation: i work with an image background wich simulate item like buttons, image, text... etc. On this image, i put buttons, image, and text (buttonview textview etc...) and place it precisely on their places on the image. This solution is very powerful to have good design BUT, if i change the resolution of the screen, and/or its size, each item won't be at its place, and will be translated (horiz and/or vertic) for some "dp"... (and yes i use dp, not mm or px or whatever)
I'm really embarrased because i think thanks to "dp" it keep proportionnality but.. not !
My question is how can i fix my items at their places on the image background, for different screen size/resolution !!
Thanks in advance everyone,
My Best From Lyon,France
First realise that if you want to make it pixel perfect for all screen sizes your out of luck.
Second accept that you can't make it perfect for all screen sizes.
Third you can get far with creating different layout for different screen sizes. You can read a lot about supporting multiple screen sizes here. One important thing to take from here is that you can make layout for the different screen sizes or different density sizes.

Java : How to tint this PNG programmatically?

Within the frame of a chess applet, I have a few sets of such greyscale/black & white (not sure) :
Is there any way to give a color tint to a PNG picture via Java Code ? Tried to google the matter and didn't find anything really matching what I'm looking for.
For the following piece for example, I'd like to give it white/yellow tint for the White player, and a flavour of black for the Black player. The idea of setting the color dynamically is to tweak themes at runtime.
It would be a lot simpler to give your program translucent images (PNG) which are plain coloured (plain or gradient) in the colours you want, and have a certain % of transparency (you can do that in photoshop/illustrator in 1min).
Then programmatically merge the tint image (preserving transparency) with the other image underneath.
Check this SO post for how to merge two images:
Merging two images
I found this on StackOverflow. It's pretty good explanation, so I won't bore you with any additional details :) Hope that helps: Applying a tint to an image in java

Categories