Text to PixelGrabber

  • Thread starter Luc The Perverse
  • Start date
L

Luc The Perverse

(feel free to jump ahead to java specific part)

***Background***

Ok I give up!

I am designing a program to display ASCII art to represent a picture.
(Purely practice, no "real" use for such a program) but the characters I use
to represent various shades of luminous intensity have been hand picked and
are very few.

I want to "count" the number of pixels used for each of the 96? typeable
characters (I'm using courier new) and assign them a luminous intensity, in
the event of a "tie" I will apply some sort of simple algorithm which favors
the pixels being most spread out (by taking luminous intensity of the 4
quadrents of the character and applying a formula to calculate the
difference)

***Java Specific Part***

I see examples for extracting pixels from class type "Image" but I can't
seem to figure out how to generate an "Image" from a font and a text string.
Can someone point me to an example, or show me one here?
 
A

a249

I see examples for extracting pixels from class type "Image" but I can't
seem to figure out how to generate an "Image" from a font and a text string.
Can someone point me to an example, or show me one here?

First comes the RTFM then the perversion

Create BufferedImage
Get Graphics2D from BufferedImage
Set font on Graphics2D
Draw string on Graphics2D
Do pervert things with BufferedImage
 
H

hiwa

(feel free to jump ahead to java specific part)

***Background***

Ok I give up!

I am designing a program to display ASCII art to represent a picture.
(Purely practice, no "real" use for such a program) but the characters I use
to represent various shades of luminous intensity have been hand picked and
are very few.

I want to "count" the number of pixels used for each of the 96? typeable
characters (I'm using courier new) and assign them a luminous intensity, in
the event of a "tie" I will apply some sort of simple algorithm which favors
the pixels being most spread out (by taking luminous intensity of the 4
quadrents of the character and applying a formula to calculate the
difference)

***Java Specific Part***

I see examples for extracting pixels from class type "Image" but I can't
seem to figure out how to generate an "Image" from a font and a text string.
Can someone point me to an example, or show me one here?

Do drawString() into an Image or BufferedImage.
 
M

Mark Space

Luc said:
I want to "count" the number of pixels used for each of the 96? typeable
characters (I'm using courier new) and assign them a luminous intensity, in
the event of a "tie" I will apply some sort of simple algorithm which favors
the pixels being most spread out (by taking luminous intensity of the 4
quadrents of the character and applying a formula to calculate the
difference

First, what the other guys said, with regards to you original problem.

Second, though, why pick the pixels that are most "spread out?" I'd
pick the one that has the most shading where you want it, in effect
sub-sampling the text images.

For example, if you detect that a character J is lighter in the upper
left quadrant than the character K, and your original image also has a
lighter patch in the upper left in that position, why use the more
"spread out" character? Use the best match...

'course, maybe I misunderstood and you're doing this already...
 
L

Luc The Perverse

Mark Space said:
For example, if you detect that a character J is lighter in the upper left
quadrant than the character K, and your original image also has a lighter
patch in the upper left in that position, why use the more "spread out"
character? Use the best match...

'course, maybe I misunderstood and you're doing this already...

Currently I'm using a single character to represet a single pixel in an
image. Obviously if I get better at detecting luminous intensity inside an
ascii character I may be able to "blur" torwards other pixels or possibly
represent multiple pixels within a single ASCII character.

First thing's first :) Besides, I'm still having fun.
 
L

Luc The Perverse

First comes the RTFM then the perversion

Create BufferedImage
Get Graphics2D from BufferedImage
Set font on Graphics2D
Draw string on Graphics2D
Do pervert things with BufferedImage

Thanks to you and hiwa :)

I will go on my way and do my pervert things.

As for the RTFM part - do you mind answering a jeopardy style question?

This is the correct google search which would have led me to this
information. ;)
 
J

Joshua Cranmer

hiwa said:
Do drawString() into an Image or BufferedImage.
Image has no drawString() method. What you mean is
image.getGraphics().drawString().
 
L

Lars Enderin

Luc The Perverse skrev:
Currently I'm using a single character to represet a single pixel in an
image. Obviously if I get better at detecting luminous intensity inside an
ascii character I may be able to "blur" torwards other pixels or possibly
represent multiple pixels within a single ASCII character.
Your use of "character" is imprecise, and why do you mention ASCII? I
think you should handle bytes, not characters.
 
L

Luc The Perverse

Lars Enderin said:
Luc The Perverse skrev:
Your use of "character" is imprecise, and why do you mention ASCII? I
think you should handle bytes, not characters.

No point in arguing over semantics. I am now converting JPG files into
beautiful ASCII art!

Speaking of which - I believe the representing pictures using standard
characters is considered "ASCII art" even if the character set is not ASCII.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top