Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-05-2009, 03:52 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Question 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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 03-05-2009, 10:41 PM
Darryl.Burke's Avatar
Senior Member
 
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 726
Rep Power: 2
Darryl.Burke is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-08-2009, 02:07 PM
Senior Member
 
Join Date: Jan 2009
Posts: 359
Rep Power: 2
toadaly is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-08-2009, 04:49 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Default
Both of these are what I was thinking.
__________________
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 03-10-2009, 04:10 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Question how to construct in internal buffered image
Originally Posted by Darryl.Burke View Post
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)
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:
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>());
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.

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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 03-10-2009, 04:15 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Default setting the font
Originally Posted by toadaly View Post
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.
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.

Originally Posted by toadaly View Post
There's probably a better way to do it by directly calculating pixels from the font, but this approach is simple and works.
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 03-11-2009, 05:03 AM
Senior Member
 
Join Date: Jan 2009
Posts: 359
Rep Power: 2
toadaly is on a distinguished road
Default
Originally Posted by Nicholas Jordan View Post
I found no way to construct a BufferedImage except to get one preconstructed from a graphics object
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);
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 04-05-2009, 05:45 AM
Member
 
Join Date: Apr 2009
Posts: 4
Rep Power: 0
hyz_zsu is on a distinguished road
Default
Originally Posted by toadaly View Post
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);
Hi, I try to get the raw data of the image by your method, but the complier said that "The method getPixels(int, int, int, int, int[]) is ambiguous for the type WritableRaster", any suggestion?
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 04-05-2009, 07:15 AM
Senior Member
 
Join Date: Jan 2009
Posts: 359
Rep Power: 2
toadaly is on a distinguished road
Default
Cast the 'null' to an int[].

...wr.getPixels(0,0,width,height,(int[]) null);
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
having problem in writing a text data to an image filr in JDE -Blackberry !!1 sanmanlan Other IDEs 0 03-05-2009 07:18 AM
Listing all available fonts provided in the system Java Tip java.awt 0 06-23-2008 12:06 AM
Converting multiple banded image into single banded image... Image enhancement archanajathan Advanced Java 0 01-08-2008 06:29 PM
no of fonts and cells exceeding error in excel sheet. iimasd AWT / Swing 0 11-06-2007 07:58 AM
OS 10.4 - Help with Java in Yahoo! Games - Fonts Unreadable? acleme1 Java Applets 3 07-16-2007 12:22 PM


All times are GMT +2. The time now is 06:03 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org