• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Draw text on image

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm facing the same issue described in https://coderanch.com/t/341758/java/Printing-text-image-text and couldn't find any solution yet.

Problem: Image is having resolution of different Sizes. I want to apply the given font-size irrespective of the image resolution.

Case1: Image should be read, text should be applied in Windows Server and image will be saved in the folder which will be viewed by windows/mac/ubuntu users
Case2: Image should be read, text should be applied in linux Server and image will be saved in the folder which will be viewed by windows/mac/ubuntu users

Currently:
Font is applied but font is getting displayed as smaller in Windows. Not tested in linux

What is the best practice on handling or applying text on image ?
The image would be of different resolution, however user wants to apply the font size as like he sees in the ms-word ...

Assume the user puts the image in an image editor irrespective of resolution, add font size 25 which he sees in the editor and wants to see the same to be applied to the image.

Thanks
 
Rancher
Posts: 3288
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post a SSCCE demonstrating your problem.
 
Chris Mary
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sample Code Snippet






public static void main(String[] args) throws Exception {
   final BufferedImage image = ImageIO.read(new URL(
           "https://upload.wikimedia.org/wikipedia/commons/6/67/Taj_Mahal_in_India_-
   _Kristian_Bertel.jpg"));
   Font font = new Font("Arial", Font.BOLD, 32);
   Graphics g = image.getGraphics();
   g.setFont(font);
   g.drawString("Welcome To Taj Mahal!", 100, 100);
   g.dispose();

   ImageIO.write(image, "png", new File("e:\\Taj_Mahal.png"));
 }
 
Saloon Keeper
Posts: 9831
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and what happened? Too big? Too small?

What were the pixel dimensions of the image? Try again with a smaller image and then again with a bigger image.  What happens?
 
Chris Mary
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to apply the font irrespective of the resolution but i will put the image in rectangle box of size

in a web editor frame. The user just view the image in the editor and apply the font for the image....

 
Rob Camick
Rancher
Posts: 3288
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suggestion removed.

A new thread has been created merging multiple questions into a single topic: https://coderanch.com/t/754939/java/Proper-Setting-Font-Size-Text
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic