Results 1 to 9 of 9
- 03-05-2009, 02:52 PM #1
how to get raw image data for fonts
As part of a bigger project I am working on, I need to be alble to get the images of fonts brought to an array of pixel values, which would be used as a training set in some advanced work on artificial intelligence. The only thing I can think of is to do graphics.getGrapics() the draw string in each of the fonts on that graphic object but everyting I can find necessitates having a graphics object come in from the system.
I need to list fonts, then have each of those fonts draw ascii 0x20 through 0x7e and be able to get the [][] or [] as one would normally view [][] on the screen or that same data as a flat dataspace that I can do offsets to make a Matrix. I have searched the code but have not gotten any starting places located.
The data can be float or int or 1/0 valued, it does not matter - I just need work the raw values from code rather than tediously, manually generating data by looking at the displayed rendering.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 03-05-2009, 09:41 PM #2
I guess you can drawString to a BufferedImage of TYPE_BYTE_BINARY and use the form of getRGB that returns an int[] (which will be in RGB color space [000000] and [FFFFFF], but you can reduce it to 0/1 binary easily enough)
HTH, db
- 03-08-2009, 01:07 PM #3
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
Oddly, I've had to do this before as well. What I did (for better or worse), was to construct a BufferedImage large enough for every character in the font (the size can be obtained from FontMetrics), then drew the character to the graphics, grabbed the resulting pixels, and made a 2d array containing a 1 everywhere the associated pixel was nonzero.
There's probably a better way to do it by directly calculating pixels from the font, but this approach is simple and works.
- 03-08-2009, 03:49 PM #4
Both of these are what I was thinking.
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 03-10-2009, 03:10 PM #5
how to construct in internal buffered image
I found no way to construct a BufferedImage except to get one preconstructed from a graphics object supplied in a paint() .... the best I can come up with is:
obviously the [] could be made bigger and I would not unroll the loop for a default internal Buffered Image initialization ... the data will be coming in ( from the JNI work in the static linking post ) as 8-bit grayscale default dib with no compression or any standard cs ops deriving from known optimizations, that's the license spike provides - anything requiring any brains such as will be coming in from known commercial traffic gets passed to him for commercial use.Java Code:this.notAnImage=new int[12]; notAnImage[0] =0x128; notAnImage[1] =0x128; notAnImage[2] =0x128; notAnImage[3] =0x128; notAnImage[4] =0x128; notAnImage[5] =0x128; notAnImage[6] =0x128; notAnImage[7] =0x128; notAnImage[8] =0x128; notAnImage[9] =0x128; notAnImage[10]=0x128; notAnImage[11]=0x128;//zarfOCR.dll // = new java.awt.image.BufferedImage(java.awt.image.ColorModel.getRGBdefault(),java.awt.image.Raster.createPackedRaster(java.awt.image.DataBuffer.TYPE_BYTE,4,3,notAnImage, new java.awt.Point()),false, new java.util.Hashtable<java.lang.String,java.lang.String>());
I worked on this as deep as I could grasp what is going on, the comment marker is to remove the code during prototyping - the small array should actually be grapics big enough to do object.drawString() for ascii 0x20 through 0x7e inclusive, at any font size that I can get constructed.
The instructor ( a double degreed board member of IEEE ) suggests using the smallest size that will work, for me what is practical for that is "any size that will work" as I can let the machine run for a hundred hours building the learning sets. One of the things I will get to today is g5 - which has an abundance of powerful optimizations for building the learning sets.
What is hanging the plan here is constructing a default ImageProducer of sufficient correctness that I can call draw string on it, listing the fonts and reducing the selection set to a sensible set is within my skills, though will involve significant manual methods such looking at the system font tool and so on....Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 03-10-2009, 03:15 PM #6
setting the font
Call setFont(...) on the graphics object then call getMetrics() ?... seems to involve an extra step,... tried to do this once before and drilled in on exactly this issue.
The tradional, known matter of getting the [][] from the font, has to be done with code - then efforts fail on how to get the information as the original coder was coding for routine use of the information appliance, not for developers.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 03-11-2009, 04:03 AM #7
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
Java Code:...supposing you found the width and height from FontMetrics... BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY); Graphics2D g = (Graphics2D) image.getGraphics(); g.setColor(Color.white); g.fillRect(0,0,width,height); g.setColor(Color.black); g.drawString("A",0,0); g.dispose(); WritableRaster wr = image.getRaster(); int[] pixels = wr.getPixels(0,0,width,height,null);
- 04-05-2009, 04:45 AM #8
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
- 04-05-2009, 06:15 AM #9
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
Similar Threads
-
having problem in writing a text data to an image filr in JDE -Blackberry !!1
By sanmanlan in forum Other IDEsReplies: 0Last Post: 03-05-2009, 06:18 AM -
Listing all available fonts provided in the system
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:06 PM -
Converting multiple banded image into single banded image... Image enhancement
By archanajathan in forum Advanced JavaReplies: 0Last Post: 01-08-2008, 05:29 PM -
no of fonts and cells exceeding error in excel sheet.
By iimasd in forum AWT / SwingReplies: 0Last Post: 11-06-2007, 06:58 AM -
OS 10.4 - Help with Java in Yahoo! Games - Fonts Unreadable?
By acleme1 in forum Java AppletsReplies: 3Last Post: 07-16-2007, 11:22 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks