Results 1 to 2 of 2
Thread: cant store images
- 01-10-2011, 11:05 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 13
- Rep Power
- 0
cant store images
Midlet class
NewClass1.javaJava Code:public void startApp() { Vector v = new Vector(); v.addElement("aaaa"); v.addElement("bbbb"); v.addElement("cccc"); NewClass1 nc = new NewClass1(); Vector c = nc.getImages(v); OpenRecordStore("imagestore"); for (int i = 0; i < c.size(); i++) storeImage((Image)c.elementAt(i)); CloseRecordStore(); } public void OpenRecordStore(String rmsNAme) { try { rs = RecordStore.openRecordStore(rmsNAme, true); } catch(Exception e){} } public void CloseRecordStore() { try { rs.closeRecordStore(); } catch(Exception e){} } public void storeImage(Image image) { int width,height; try { System.out.println(rs.getNextRecordID()); width = image.getWidth(); height = image.getHeight(); int imageData[] = new int[width*height]; image.getRGB(imageData, 0, width, 0, 0, width, height); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(outStream); for (int i = 0; i < imageData.length; i++) dataOut.writeInt(imageData[i]); rs.addRecord(outStream.toByteArray(), 0, outStream.toByteArray().length); dataOut.close(); outStream.close(); } catch(Exception e) {} }
the result of print is 1,2,2. only the first image gets stored. i checked the images. i created a form inside the startapp method and appended every image into it. i was able to see them no problem. i didnt even have to cast the elements to Image (formx.append(data.elementAt(0));Java Code:import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.util.Vector; import javax.microedition.io.Connector; import javax.microedition.io.ContentConnection; import javax.microedition.lcdui.Image; public class NewClass1 { Vector data1; public NewClass1 () { data1 = new Vector(); } public Vector getImages(Vector data) { for (int i = 0; i < data.size(); i++) { try { ContentConnection connection = (ContentConnection) Connector.open("http://localhost/tutorial/images/" + data.elementAt(i) + ".jpg"); DataInputStream iStrm = connection.openDataInputStream(); ByteArrayOutputStream bStrm = null; Image im = null; byte imageData[]; int length = (int) connection.getLength(); if (length != -1) { imageData = new byte[length]; iStrm.readFully(imageData); } else // Length not available... { bStrm = new ByteArrayOutputStream(); int ch; while ((ch = iStrm.read()) != -1) bStrm.write(ch); imageData = bStrm.toByteArray(); bStrm.close(); } im = Image.createImage(imageData, 0, imageData.length); data1.addElement(im); if (connection != null) connection.close(); if (iStrm != null) iStrm.close(); if (bStrm != null) bStrm.close(); } catch (Exception e) { e.printStackTrace(); } } return data1; } }
shouldnt it be 1 2 3? shouldnt i b able to store all the images? the sizes are small. 326 by 92 dimensions.
i checked the size of data1. it downloaded all 3 images.
if i try to print the details of the rms, i only get details for the first pic. the second one doesnt even get store. how come? is the recordstore full alraedy? :S
these two classes arent my final version of course. i no it looks a bit ugly but im just putting everything together for you.
Thank you.
- 01-11-2011, 09:38 AM #2
Member
- Join Date
- Sep 2009
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
how to mark on 2 images at a time,both images are on different JPanel
By smitharavi in forum AWT / SwingReplies: 0Last Post: 12-16-2010, 05:14 PM -
how to scroll 2 images at a time(synchronisation),both images are on different panels
By smitharavi in forum AWT / SwingReplies: 4Last Post: 12-16-2010, 04:32 PM -
how to store images in access database
By sridarshan in forum JDBCReplies: 11Last Post: 06-26-2010, 02:26 AM -
How do I store images in a zip file in Java
By mglover in forum Advanced JavaReplies: 1Last Post: 06-11-2010, 03:53 PM -
Extract xml to store into db
By palanikumark in forum Advanced JavaReplies: 3Last Post: 06-06-2008, 03:09 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks