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










share|improve this question























  • 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














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










share|improve this question























  • 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












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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 (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
















  • 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















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo