Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Image to byte[] to access database

843807Jul 19 2001 — edited Jun 26 2006
I have been trying to get an image into an access database. I have read that you need to convert it to a byte array to do this. This is the code I have right now, and it throws a ClassCastException. Any ideas what I'm doing wrong?!
Image img = Toolkit.getDefaultToolkit().getImage("C:\\isas\\isas\\images\\bj5.gif");
	
	
int[] pix = new int[img.getWidth(null) * img.getHeight(null)];
PixelGrabber pg = new PixelGrabber(img, 0, 0, img.getWidth(this), img.getHeight(this), pix, 0, img.getWidth(this));
pg.grabPixels();


byte[] pixels = new byte[img.getWidth(this) * img.getHeight(this)];
pixels = (byte[])pg.getPixels();

pstmt.setBytes(1, pixels);
pstmt.executeUpdate();
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 24 2006
Added on Jul 19 2001
17 comments
341 views