Hi

Can someone please let me know which classes, objects, etc I should use into to convert an image file (.png, probably) to a printable string in Java?

The image will be around 100px square and I presume I could scan 1px lines into arrays, etc? I'm hoping Java has a predefined method to handle this kind of thing.

I'm familiar with OOP and most programming terminologies (I've been in IT forever), but unfortunately I just don't have time to "become one" with Java - at least not before my client expects delivery!

Assume the basic output to be a matrix, showing one of two images in each cell.

Thanks in anticipation.

Recommended Answers

All 8 Replies

What would the String contain? The pixel RGB values as decimal numbers separated by commas?
Seems like a very strange conversion. Like a debug output for looking at the structure of an image.

Hi, NormR1

Thanks for getting back to me, so quickly.

For demonstration prposes recently, I created a simple matrix image for my client.

Some of the cells in the matrix had a coloured tick, otherwise, the box was left blank. Pretty simple stuff.

They liked the idea of a colourful, online alternative to the usual static, paper documentation and asked to have it provided online, on-demand.

I have the formatted data ready for input, and I am now trying to print rectangles representing one of the two states, rather than the unatractive ASCII version, e.g. "| N | Y | N |" ..."

So, instead of writing "N" or "Y", I want to output a 10px by 10px image, say, a red box or green box.

How do I do this?

I can handle the logic; it's just the convoluted mechanics of loading a string with the contents of an image.

Hope this helps.

Cheers

I want to output a 10px by 10px image, say, a red box or green box.

Where is this 10x10 image to be displayed? In a GUI?
You can add a JPanel to a container, override the JPanel's paintComponent method and add calls to various Graphics class methods to draw the rectangles.

the convoluted mechanics of loading a string with the contents of an image.

That makes no sense to me. How to load the contents of an image into a String???

OK, I appreciate your patience and I'll try once again to explain my problem.

- I used Fireworks to create a .png image file, which shows a typical x/y matrix
- That image file is linked to a RoboHelp snippet and parent help topic
- The compiled WebHelp application provides an web page for my client, who wants to see "real" data in the same format
-I wrote a VB script that produces a text file, which can replace the graphic if I can't produce the graphic myself

I want to do this in Java, to drag myself int the modern world.

I can probably manage this


, a component of a WebHelp topic.

At the moment, I am writing characters ("N", "Y", etc) to a file, as an alternative

I appreciate your patience and I'll try once more to explain my problem.

- I used MX Fireworks to create a .png image file, showing a typical Y/N matrix of certain relationships in the client's database
- I then created a PDF version of the image, for clarity and archival purposes
- the PDF file is linked by reference to a RoboHelp snippet, which is included in its parent RH topic
- a compiled WebHelp application provides a web page for my client's reference

No problems so far.

- the client now wants to see 'live' data in the same format as the approved test page
- to do this, I put together a VB script that runs nightly against use the client DB, recreating the unattractive, but accurate text version of the matrix
- as before, I create a PDF version of the generated .txt file

Still OK.

- the next step is to rework things in Java, replacing the "Y" and "N" characters by appropriate images (say, green and red boxes)
- as there will multiple rows and columns in the matrix, I want to loop through my input datastream, preloading the output text record with a series of coloured images, rather than "Y" or "N" characters
- each fully loaded row record will be written as a record to the new text file, which will be converted to PDF, etc as before

Java's capability of replacing the "Y" and "N" strings with a green or red box is what I need explaining, please.

Thank you.

Java's capability of replacing the "Y" and "N" strings with a green or red box i

Where/how are the "Y" and "N" Strings being displayed?

preloading the output text record with a series of coloured images

Strings do NOT contain anything but characters.
Sounds like you want to generate HTML with references to colored images.

Take the bytes in an image file and encode it to printable character combinations with base64.

Or get some slick image scan code and if the image is a picture of a flower,
set the String to "Picture of a flower"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.