Note that there are some explanatory texts on larger screens.

plurals
  1. POJ2ME:Downloading an Image from server and saving on Mobile
    text
    copied!<p>I'm trying to download an image from server and save the image on mobile phone.I'm able to download the image but I need to resize the image and then store the image to mobile.</p> <p>the code is like this.</p> <pre><code>public void requestPlatform(String strURL) throws IOException { try { System.out.println("requestPlatform"); byte [] imageBytes = null; if ((im = getImage1(strURL)) != null) { im=resizeImage(im, width, height); if(im!=null) { System.out.println("Image"); } else System.out.println("NoImage"); imageBytes=get_Byte_Array(im); fileCon=(FileConnection)Connector.open("file:///root1/photos/diwali1.jpg",Connector.READ_WRITE); fileCon.create(); if(fileCon.exists()) { System.out.println("File created"); } else { System.out.println("File not created"); } out = fileCon.openDataOutputStream(); if(imageBytes!=null) { out.write(imageBytes, 0, imageBytes.length); } if(out!=null) { out.close(); } if(fileCon!=null) { fileCon.close(); } im2=Image.createImage(imageBytes, 0, imageBytes.length); canvas.repaint(); } } catch (Exception e) { System.err.println("Msg: " + e.toString()); } } public byte[] get_Byte_Array(Image img) { int[] imgRgbData = new int[img.getWidth() * img.getHeight()]; byte[] imageData2 = null; try { img.getRGB( imgRgbData, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight() ); } catch( Exception e ) { } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream( baos ); try{ for( int i = 0; i &lt; imgRgbData.length; i++ ) { dos.writeInt( imgRgbData[i] ); } imageData2 = baos.toByteArray(); baos.close(); dos.close(); }catch(Exception e) { } return imageData2; } </code></pre> <p>The problem is when I'm trying to resize the image and then save it on phone it just creates a file but there is no image.So i think there is some mistake while i'm converting image to byteArray.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload