This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to change text in a image(.gif file) through Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to change text in a image(.gif file) through Java" Watch "How to change text in a image(.gif file) through Java" New topic
Author

How to change text in a image(.gif file) through Java

Javed Akhtar
Greenhorn

Joined: Dec 20, 2000
Posts: 18
I am displaying an image ie .gif file in my java application.
There is a button in my java application.When I click button,
I wants to change a text in my gif file.For example,a text "Welcome" is dislaying in gif file when i am running java application,when I am clicking button,I wants to change text from "Welcome" to "Welcome to Java's World" in same gif which is displaying in my java application.
Kindly get back to me as early as posible.
Thanking very much
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
You could just have a plain image (no text - just the background) that you get a graphics Object from and then use this to write text in. For example,

Otherwise, just use two images and swap them when the button is clicked. If you only have two messages, this is probably the easiest.
Sean
Javed Akhtar
Greenhorn

Joined: Dec 20, 2000
Posts: 18
Hello Sean,
Thanks for reply.But it doesn't solve my problem as
Image image = getImage( getCodeBase(), "myImage.gif");
Graphics imageG = image.getGraphics();
imageG.getGraphics(),posible only when when I use
createImage(w,h)method.But I am already having gif file in which
there is a text and I have to change that text after certain actionevent.Kindly try help me .
Thanks
Javed
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
I'm afraid there's not much you can do if you have to work with an Image that already has text in it. The problem is that text in an image such as a .gif is not recognized a text once it is encoded as an image. The text is indistinguishable from the rest of the pixels. Theoretically, you could use a sophisticated edge finding algorithm to detect the text within the image and then erase it using another algorithm to paint over it based on the surrounding colors, but this would be quite difficult and probably not the answer you looking for. The only thing I can recommend is taking the original image into Photoshop or Graphic Converter and manually remove the text as best as you can. Then create two new images with the text you need. Then simply swap the images as neccessary. Sorry, I couldn't be more help.
Sean
Golam Newaz
Ranch Hand

Joined: Jan 08, 2001
Posts: 64
Friend Javed Akhter,
I understood what you are looking for. Recently so many
websites are uploaded on internet who are using java applet
button. I think you are interested to make that kind of applet
isn't it? Ok. Actually, the way you are thinking it is not
correct. You have to use different button image .gif files giving same width and same height, but different title like
"Welcome" with one image and " Welcome to java's world" with
another image. But when you will make your image you have to
adjust your title alignment, ok.Then you have to think other java code. If you have knowledge about html. It would be
a piece of cake to you. Look at the followings:
You need three image variables like these:
import java.applet.*;
import java.awt.*;
public class button extends applet{
Image currentimage; // declare for temporary image.
Image normalimage; // declare for image one.
Image mouseoverimage; // declare for image two.
public init(){
// here load your image using Mediatracker and initialise your
// two images.
currentimage=normalimage;

// do other try{} block with catch exception
//........
} // end of init()
public boolean Mouseenter(event evt, int x, int y)
{
currentimage=mouseoverimage;
update(getGraphisc(});
return true;
}
public boolean mouseExit(Event evt, int x, int y)
{
currentimage=normalimage;
update(getGraphics());
return true;
}
}
Kindly think deeply and find syntex error and solve your
problem.
Thanks,
Golam Newaz
Javed Akhtar
Greenhorn

Joined: Dec 20, 2000
Posts: 18
Mr. Newaz,
Thanks for your response.But sorry it does'n help me.
My first requirment is I have to display image in a frame ie in a application not in applet,so it can't support getGraphics()
as you explain above.I am repeating my problem below kindly try
to solve it.
Problem:
I have to display an image in a Standalone application
say a frame.After a click event I wants to change a text (which is already in image).For example in image a text "Java" is
presents and I wants to change it to "Welcome to Java's world".
It means that I am playing with a gif file which is saved in Harddisk.Kindly help me how to do it.
Next I wants to adjust size of image according to size of frame,ie for a frame of 300*300 should display complete image
and it should display completely in a frame of 800*600
means my application should adjust size of image according to size of frame.
Kindly try to help for both problem.
Thanks
Javed
Golam Newaz
Ranch Hand

Joined: Jan 08, 2001
Posts: 64
Hi Javed,
I am sorry that i did a little mistake in making sense about
your problem. Looking at the things you are expecting right now as per your latest message, i can consider it to way,ok. First
you clear me about it, whether you want to show your image
like the opening page of javaranch.com in where you find
buttons. If you leave your button on that, they show message
at the beneath of the buttons, are you expecting to show
your text in that way into frame OR
Kindly visit into this site http://webbangladesh.com/game/akash.html ,in where you will
find a game named "Moshok Destroyer", recently i developed.
Once you upload that game, kindly click About button you
will find a frame in where i uploaded images. But i want to
say that it is a little bit harder to show your image into
application i.e. frame.
Awaiting your reply,
Golam Sayeed Newaz
Javed Akhtar
Greenhorn

Joined: Dec 20, 2000
Posts: 18
Hello Newaz,
Basically I am developing a java application as a front-end.I am using a .gif file in which there are diff text.When I click on these text it fires an event,and perform its respective work ie respectve area works as button.I want to change these text at runtime ie user can change text in application.
For these purpose i need above help.Kindly think over this problem and help me.
Thanks. Awaiting your reply.
Javed

Anh Nguyen
Greenhorn

Joined: Jan 24, 2001
Posts: 18
Dear ,
I can think of a way to go around it . Hope that it would help . As all of the answer above , there is no way that you can actualy change anything in the .gif file (well , actualy you can erase the appearance of it ). So why don't you create another .gif which contains only the background . Then whenever the user click the button , you can update the background-only-image with the old one and draw a new text line in it . That way even the user can write whatever they want to appear in the image (ex you can have a text field that user can type in, then click OK and that text appear in you image or you can just write whatever you want ). And it also has no flick at all .

------------------
... No one can escape .......
Heavenly Evil Knight


... No one can escape .......<BR><B>Heavenly Evil Knight</B>
 
wood burning stoves
 
subject: How to change text in a image(.gif file) through Java
 
Similar Threads
Displaying gifs...
graphics2d
how to save text as gif ?
ImageIcon Update Questions : Is it Possible?
Displaying an image in a servlet