A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Convert gif to byte array
Keith Harrison
Greenhorn
Joined: Mar 04, 2006
Posts: 15
posted
Mar 04, 2006 07:35:00
0
Hello.
I have the following method:
public static byte[] getPhoto (int iNumPhoto) throws Exception, SQLException{ try{ System.out.println("Photo ID=" + iNumPhoto); conn = QueryToolDBConnection.getConnection(); conn.setAutoCommit (false); Blob img ; stmt = conn.createStatement (); // Query req = "Select image From Images Where ImageID = " + iNumPhoto ; rset = stmt.executeQuery ( req ); while (rset.next ()) { img = rset.getBlob(1); imgData = img.getBytes(1,(int)img.length()); } } catch (SQLException exception){ System.out.println("ERROR in getPhoto(" + iNumPhoto + "): " + "Error cause by query Statement."); System.out.println(exception.toString()); System.out.println(req); } finally { try{ stmt.close(); conn.close(); }catch (SQLException ignored){} } System.out.println("imgData:" + imgData); if(imgData == null){ >>>>>>>>>>>>>>>>>>>>>> HERE <<<<<<<<<<<<<<<<<<<<<< }else{ return imgData ; } }
At the point where I have typed >>> HERE <<< I want to read in a gif image from localhost root directory (i.e "/images/noImage.gif") and convert it to a byte array to use as return.
Seems simple enough but need guidance!
Thanks to anybody who can help
Keith
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35443
9
posted
Mar 04, 2006 08:14:00
0
Welcome to JavaRanch.
A quick Google search found
this highly relevant code example
.
Android apps
–
ImageJ plugins
–
Java web charts
Keith Harrison
Greenhorn
Joined: Mar 04, 2006
Posts: 15
posted
Mar 04, 2006 08:39:00
0
Thank you very much.
I agree. Here's the link:
http://aspose.com/file-tools
subject: Convert gif to byte array
Similar Threads
Displaying BLOB image in a jsp page
Streaming image data into JSP
downloading image
wanna send image bytes to server
How to display images directly from database?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter