• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Proper Way Of Setting The Font Size for Text Rendering In 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,

Below is the code



The problem is after the image is written, the font size is small when i opened it

1. How to determine the size based on the image resolution? for example the given font size should be changed or multiplied by 2 or 3  or 4 or...based on the resolution
2. I'm looking for a kind of font just in MS-WORD and it will be same when i opened image anywhere

Please advise.

Thanks
 
Saloon Keeper
Posts: 10750
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't believe you can use image resolution to determine the font size, you'd have to use the image dimensions in pixels. Then it would depend on how you were viewing the image as to how large the font appears. If the image is scaled to fit a screen the font would appear one size. If it were scaled to fit inside a window it would be another. If it were scaled to fit  a Word doc, yet another.

Do you have the case where all the source images are about the same size AND you have one critical output situation where the fonts all have to appear roughly the same size?
 
Carey Brown
Saloon Keeper
Posts: 10750
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
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
Hi,

Is there is any FONT utility is available with respect to resolution?

Ex:
Font 16 would be higher in small resolution
Font 16 would be medium size in medium resolution
Font 16 would be small size in higher resolution

I want to multiply the font size according to the resolution

For example, a title for an image

Please advise.

Thanks
 
Carey Brown
Saloon Keeper
Posts: 10750
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think you are properly applying the term "resolution". Resolution is in pixels per inch, like 72 or 240, and it ONLY has meaning when displaying things to a physical scale such as printing on paper. The resolution can be anything and still display properly with most software because almost all software goes by the image dimensions in pixels, not resolution.
 
Carey Brown
Saloon Keeper
Posts: 10750
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
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
Hi,

Below is the java API of FONT class - https://docs.oracle.com/javase/7/docs/api/java/awt/Font.html#Font(java.lang.String,%20int,%20int)

public Font(String name,
   int style,
   int size)

Creates a new Font from the specified name, style and point size.

It says size - the point size of the Font

I could understand it. Can someone explain in detail?

Thanks
 
Marshal
Posts: 8869
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I'm not familiar with this API myself, but I found some article, which sounds convincing, what it means in general. So I think it well applies to this API as well.

https://www.computerhope.com/jargon/f/font-size.htm
https://practicaltypography.com/point-size.html

But in different words I could say it is a Font size.
 
Rancher
Posts: 3324
32
  • 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.

That is create two Fonts each with a different point size and display the text on a label.

If you still don't understand the difference, then ask a specific question.

The point is to try using the method first before asking the question.
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still not sure I understand your question.

Maybe you can use the GraphicsDevice class and then get the DisplayMode object. You can then access the screen width/height and determine which Font size you want to use for your image.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Mary wrote:Hi,

Below is the code
The problem is after the image is written, the font size is small when i opened it


The text drawn on the image will be about 32 pixels tall, since you specified 32 as the font size.

Whether or not that should be considered "small" is subjective. The image itself has a height of 2437 pixels, so 32 would be about 1.3% of that.

If you want a bigger font, then change the 32 to something else, like 128, or image.getHeight()/10. [But if you use image.getHeight()/10 then you will probably also want to change the Y value in the call to drawString().]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic