aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Edit text in image using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Edit text in image using Java" Watch "Edit text in image using Java" New topic
Author

Edit text in image using Java

Avinash Yn
Greenhorn

Joined: Nov 21, 2012
Posts: 4
Hi, Is there a way to edit text in the image using java just like Adobe Photoshop does?

Well let me tell my requirement first.. I am working on a project in which there is a requirement for text resizing(Only width and not height). To achieve that I converted the text to image and was able to resize it. Now my query is I am unable to edit that text. I cannot save the text somewhere and use it while editing bcz there could be more than 100's of text so that would be a very bad option.

So can anyone tell me how to edit the text from the image? Is it possible in Java?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41524
    
  53
Not even Photoshop can do that if the image is a JPEG/GIF/PNG/etc. file. That's only possible if the text is saved separately from the bitmap data, like in layers in Photoshop.


Ping & DNS - my free Android networking tools app
Avinash Yn
Greenhorn

Joined: Nov 21, 2012
Posts: 4
Ulf Dittmer wrote:Not even Photoshop can do that if the image is a JPEG/GIF/PNG/etc. file. That's only possible if the text is saved separately from the bitmap data, like in layers in Photoshop.


Ok. So can you please tell me how to achieve the same in Java?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41524
    
  53
You can't. Not unless you keep two separate image files - one with the bitmap, and one with the text (which you would regenerate every time you need to change font sizes), and then overlay those images into one.
Avinash Yn
Greenhorn

Joined: Nov 21, 2012
Posts: 4
Ulf Dittmer wrote:You can't. Not unless you keep two separate image files - one with the bitmap, and one with the text (which you would regenerate every time you need to change font sizes), and then overlay those images into one.


Ok But Ulf Dittmer correct me if I am wrong, Lets say I have 2 image files now- bitmap and text. but how can I edit them as both are in the image format. I am confused. please help me out
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41524
    
  53
The file containing the text would have to have a transparent background. Then you can overlay them into a single image, as described here: http://stackoverflow.com/questions/2318020/merging-two-images
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
would showing the images as the background of a JLabel work?
then you could do whatever you wanted with the text.
Avinash Yn
Greenhorn

Joined: Nov 21, 2012
Posts: 4
Ulf Dittmer wrote:The file containing the text would have to have a transparent background. Then you can overlay them into a single image, as described here: http://stackoverflow.com/questions/2318020/merging-two-images


Hi Ulf Dittmer, After you said that we need to have text and image separately, I did that and now I am able to convert the image back to text i.e. on image click I am hiding image and showing text. but there is 1 more issue i.e. if i resize the image width and height and then click the image I get the text with unresized version (As resize is done on image and not on text). So how do I increase/decrease the font size as I resize the image.

Any idea about this? I know that this is possible because it is done in photoshop, so java also should have feature.. hope it has!!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41524
    
  53
After you said that we need to have text and image separately, I did that and now I am able to convert the image back to text i.e. on image click I am hiding image and showing text. but there is 1 more issue i.e. if i resize the image width and height and then click the image I get the text with unresized version (As resize is done on image and not on text). So how do I increase/decrease the font size as I resize the image.


Sorry, I don't understand this. You talk of "converting an image back to text", but what I advised did no such thing (which would amount to OCR). How, exactly, are you now showing text on an image, and how do the user interactions influence what's shown? Is there a server access involved?

I know that this is possible because it is done in photoshop, so java also should have feature.

Only in the sense that Java is a programming language, so whatever Photoshop does can certainly be programmed in Java as well. Photoshop is hugely complex, though, whereas Java isn't exactly a mainstay for image processing implementations. So you may have to write the code yourself.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Edit text in image using Java