BufferedImage drawString corrupted letters
up vote
0
down vote
favorite
I'm writing a program in Kotlin to run on Raspberry Pi. I'm using a small 128x64 pixel OLED display
To display a text I'm drawing it on BufferedImage and then display that image
val bufferedImage = BufferedImage(128, 64, BufferedImage.TYPE_INT_RGB)
val g = bufferedImage.createGraphics()
g.paint = Color.WHITE
g.font = Font("PixelMix", Font.BOLD, /*Font size*/8)
g.drawString("IP: 192.168.1.12", 0, 24)
g.dispose()
display.drawImage(bufferedImage, 0, 0)
link to font: https://www.dafont.com/pixelmix.font
Because screen space is very limited I use small font.
But here comes the problem - following code produces image in which the first 1
lack vertical line, while last 1
is a square.
When I do g.font = Font("PixelMix", Font.PLAIN, 10)
then 2
in 192
lacks right-most pixel row, similarly with font size 12. On font size 16 P
lacks vertical line and so on. It is just at font size 24 when everything looks acceptable, but 24 is way too big for a screen of that size.
My question now is how do I draw a string on BufferedImage so that I don't get artifacts like that?
EDIT:
At font size 10 exactly 8 pixels (vertically) are used to display a character
As for font size 8 it's 6 pixels vertically and for 16 it's 12 pixels
I did g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
, but it did not helped
kotlin bufferedimage
|
show 2 more comments
up vote
0
down vote
favorite
I'm writing a program in Kotlin to run on Raspberry Pi. I'm using a small 128x64 pixel OLED display
To display a text I'm drawing it on BufferedImage and then display that image
val bufferedImage = BufferedImage(128, 64, BufferedImage.TYPE_INT_RGB)
val g = bufferedImage.createGraphics()
g.paint = Color.WHITE
g.font = Font("PixelMix", Font.BOLD, /*Font size*/8)
g.drawString("IP: 192.168.1.12", 0, 24)
g.dispose()
display.drawImage(bufferedImage, 0, 0)
link to font: https://www.dafont.com/pixelmix.font
Because screen space is very limited I use small font.
But here comes the problem - following code produces image in which the first 1
lack vertical line, while last 1
is a square.
When I do g.font = Font("PixelMix", Font.PLAIN, 10)
then 2
in 192
lacks right-most pixel row, similarly with font size 12. On font size 16 P
lacks vertical line and so on. It is just at font size 24 when everything looks acceptable, but 24 is way too big for a screen of that size.
My question now is how do I draw a string on BufferedImage so that I don't get artifacts like that?
EDIT:
At font size 10 exactly 8 pixels (vertically) are used to display a character
As for font size 8 it's 6 pixels vertically and for 16 it's 12 pixels
I did g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
, but it did not helped
kotlin bufferedimage
out of 64 vertical pixels in the display, for your font size 10, how many vertical pixels are used to print the characters (say1
)?
– Jos Angel George
Nov 9 at 19:28
1
From the page you linked to I see:Use at 6pt, (or multiples of 6pt), anti-aliasing off
` I don't know anything about fonts but I would guess that if you have a problem with the font you would need to contact the developer.
– camickr
Nov 9 at 19:46
@camickr disabling anti-aliasing does not help. And that problem is on all fonts - Minecraft, Sans, Arial etc. No matter if it's a "pixelized" font or not
– Miku
Nov 9 at 20:07
2
And that problem is on all fonts
- then that should be the key part of your question. Now because you include the custom Font it looks like that is where your problem is. Post a proper Minimal, Complete, and Verifiable example that demonstrates the problem. The "MCVE" should use standard fonts so people on different platforms can test the code (if they wish). Maybe the problem is your platform.
– camickr
Nov 9 at 20:51
2
@Miku,You can lead a horse to water, but you can't force it to drink
. I gave my suggestions on how to improve your question to get a better answer. What you choose to do with those suggestions now and in the future is up to you.
– camickr
Nov 9 at 23:35
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm writing a program in Kotlin to run on Raspberry Pi. I'm using a small 128x64 pixel OLED display
To display a text I'm drawing it on BufferedImage and then display that image
val bufferedImage = BufferedImage(128, 64, BufferedImage.TYPE_INT_RGB)
val g = bufferedImage.createGraphics()
g.paint = Color.WHITE
g.font = Font("PixelMix", Font.BOLD, /*Font size*/8)
g.drawString("IP: 192.168.1.12", 0, 24)
g.dispose()
display.drawImage(bufferedImage, 0, 0)
link to font: https://www.dafont.com/pixelmix.font
Because screen space is very limited I use small font.
But here comes the problem - following code produces image in which the first 1
lack vertical line, while last 1
is a square.
When I do g.font = Font("PixelMix", Font.PLAIN, 10)
then 2
in 192
lacks right-most pixel row, similarly with font size 12. On font size 16 P
lacks vertical line and so on. It is just at font size 24 when everything looks acceptable, but 24 is way too big for a screen of that size.
My question now is how do I draw a string on BufferedImage so that I don't get artifacts like that?
EDIT:
At font size 10 exactly 8 pixels (vertically) are used to display a character
As for font size 8 it's 6 pixels vertically and for 16 it's 12 pixels
I did g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
, but it did not helped
kotlin bufferedimage
I'm writing a program in Kotlin to run on Raspberry Pi. I'm using a small 128x64 pixel OLED display
To display a text I'm drawing it on BufferedImage and then display that image
val bufferedImage = BufferedImage(128, 64, BufferedImage.TYPE_INT_RGB)
val g = bufferedImage.createGraphics()
g.paint = Color.WHITE
g.font = Font("PixelMix", Font.BOLD, /*Font size*/8)
g.drawString("IP: 192.168.1.12", 0, 24)
g.dispose()
display.drawImage(bufferedImage, 0, 0)
link to font: https://www.dafont.com/pixelmix.font
Because screen space is very limited I use small font.
But here comes the problem - following code produces image in which the first 1
lack vertical line, while last 1
is a square.
When I do g.font = Font("PixelMix", Font.PLAIN, 10)
then 2
in 192
lacks right-most pixel row, similarly with font size 12. On font size 16 P
lacks vertical line and so on. It is just at font size 24 when everything looks acceptable, but 24 is way too big for a screen of that size.
My question now is how do I draw a string on BufferedImage so that I don't get artifacts like that?
EDIT:
At font size 10 exactly 8 pixels (vertically) are used to display a character
As for font size 8 it's 6 pixels vertically and for 16 it's 12 pixels
I did g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
, but it did not helped
kotlin bufferedimage
kotlin bufferedimage
edited Nov 12 at 8:24
Jayson Minard
35.4k13103170
35.4k13103170
asked Nov 9 at 19:22
Miku
197
197
out of 64 vertical pixels in the display, for your font size 10, how many vertical pixels are used to print the characters (say1
)?
– Jos Angel George
Nov 9 at 19:28
1
From the page you linked to I see:Use at 6pt, (or multiples of 6pt), anti-aliasing off
` I don't know anything about fonts but I would guess that if you have a problem with the font you would need to contact the developer.
– camickr
Nov 9 at 19:46
@camickr disabling anti-aliasing does not help. And that problem is on all fonts - Minecraft, Sans, Arial etc. No matter if it's a "pixelized" font or not
– Miku
Nov 9 at 20:07
2
And that problem is on all fonts
- then that should be the key part of your question. Now because you include the custom Font it looks like that is where your problem is. Post a proper Minimal, Complete, and Verifiable example that demonstrates the problem. The "MCVE" should use standard fonts so people on different platforms can test the code (if they wish). Maybe the problem is your platform.
– camickr
Nov 9 at 20:51
2
@Miku,You can lead a horse to water, but you can't force it to drink
. I gave my suggestions on how to improve your question to get a better answer. What you choose to do with those suggestions now and in the future is up to you.
– camickr
Nov 9 at 23:35
|
show 2 more comments
out of 64 vertical pixels in the display, for your font size 10, how many vertical pixels are used to print the characters (say1
)?
– Jos Angel George
Nov 9 at 19:28
1
From the page you linked to I see:Use at 6pt, (or multiples of 6pt), anti-aliasing off
` I don't know anything about fonts but I would guess that if you have a problem with the font you would need to contact the developer.
– camickr
Nov 9 at 19:46
@camickr disabling anti-aliasing does not help. And that problem is on all fonts - Minecraft, Sans, Arial etc. No matter if it's a "pixelized" font or not
– Miku
Nov 9 at 20:07
2
And that problem is on all fonts
- then that should be the key part of your question. Now because you include the custom Font it looks like that is where your problem is. Post a proper Minimal, Complete, and Verifiable example that demonstrates the problem. The "MCVE" should use standard fonts so people on different platforms can test the code (if they wish). Maybe the problem is your platform.
– camickr
Nov 9 at 20:51
2
@Miku,You can lead a horse to water, but you can't force it to drink
. I gave my suggestions on how to improve your question to get a better answer. What you choose to do with those suggestions now and in the future is up to you.
– camickr
Nov 9 at 23:35
out of 64 vertical pixels in the display, for your font size 10, how many vertical pixels are used to print the characters (say
1
)?– Jos Angel George
Nov 9 at 19:28
out of 64 vertical pixels in the display, for your font size 10, how many vertical pixels are used to print the characters (say
1
)?– Jos Angel George
Nov 9 at 19:28
1
1
From the page you linked to I see:
Use at 6pt, (or multiples of 6pt), anti-aliasing off
` I don't know anything about fonts but I would guess that if you have a problem with the font you would need to contact the developer.– camickr
Nov 9 at 19:46
From the page you linked to I see:
Use at 6pt, (or multiples of 6pt), anti-aliasing off
` I don't know anything about fonts but I would guess that if you have a problem with the font you would need to contact the developer.– camickr
Nov 9 at 19:46
@camickr disabling anti-aliasing does not help. And that problem is on all fonts - Minecraft, Sans, Arial etc. No matter if it's a "pixelized" font or not
– Miku
Nov 9 at 20:07
@camickr disabling anti-aliasing does not help. And that problem is on all fonts - Minecraft, Sans, Arial etc. No matter if it's a "pixelized" font or not
– Miku
Nov 9 at 20:07
2
2
And that problem is on all fonts
- then that should be the key part of your question. Now because you include the custom Font it looks like that is where your problem is. Post a proper Minimal, Complete, and Verifiable example that demonstrates the problem. The "MCVE" should use standard fonts so people on different platforms can test the code (if they wish). Maybe the problem is your platform.– camickr
Nov 9 at 20:51
And that problem is on all fonts
- then that should be the key part of your question. Now because you include the custom Font it looks like that is where your problem is. Post a proper Minimal, Complete, and Verifiable example that demonstrates the problem. The "MCVE" should use standard fonts so people on different platforms can test the code (if they wish). Maybe the problem is your platform.– camickr
Nov 9 at 20:51
2
2
@Miku,
You can lead a horse to water, but you can't force it to drink
. I gave my suggestions on how to improve your question to get a better answer. What you choose to do with those suggestions now and in the future is up to you.– camickr
Nov 9 at 23:35
@Miku,
You can lead a horse to water, but you can't force it to drink
. I gave my suggestions on how to improve your question to get a better answer. What you choose to do with those suggestions now and in the future is up to you.– camickr
Nov 9 at 23:35
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232089%2fbufferedimage-drawstring-corrupted-letters%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
out of 64 vertical pixels in the display, for your font size 10, how many vertical pixels are used to print the characters (say
1
)?– Jos Angel George
Nov 9 at 19:28
1
From the page you linked to I see:
Use at 6pt, (or multiples of 6pt), anti-aliasing off
` I don't know anything about fonts but I would guess that if you have a problem with the font you would need to contact the developer.– camickr
Nov 9 at 19:46
@camickr disabling anti-aliasing does not help. And that problem is on all fonts - Minecraft, Sans, Arial etc. No matter if it's a "pixelized" font or not
– Miku
Nov 9 at 20:07
2
And that problem is on all fonts
- then that should be the key part of your question. Now because you include the custom Font it looks like that is where your problem is. Post a proper Minimal, Complete, and Verifiable example that demonstrates the problem. The "MCVE" should use standard fonts so people on different platforms can test the code (if they wish). Maybe the problem is your platform.– camickr
Nov 9 at 20:51
2
@Miku,
You can lead a horse to water, but you can't force it to drink
. I gave my suggestions on how to improve your question to get a better answer. What you choose to do with those suggestions now and in the future is up to you.– camickr
Nov 9 at 23:35