I'm new here and this is my first post..
After looking and not finding anything that works for a week.. I've decided to ask.
The problem is that i'm creating a module(function) that would output/save the image to the phone.. And after much trial and error, I could only output a currupted image.
here's the code:
I'm new to J2ME and I'm not even sure if I'm on the right track in doing this. Also, please note that my real aim is to save the image in .jpg format, not .png unlike what the code above would do. I'm planning to run this on an S60 3rd Ed.Code:public void imgOutput(Image outputImg){//Outputs the image file to directory int outImgW = outputImg.getWidth(); int outImgH = outputImg.getHeight(); int[] pixels = new int[outImgW*outImgH]; try{ outputImg.createRGBImage(pixels, outImgW, outImgH, true); }catch (Exception thisError){ switchDisplayable(null, getErrorHand()); System.err.println(thisError+": Error in Image Output"); } byte[] imgData = null; try{ ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(byteOut); for(int i = 0;i < pixels.length;i++){ dataOut.write(pixels[i]); } imgData = byteOut.toByteArray(); }catch (IOException thisError){ switchDisplayable(null, getErrorHand()); System.err.println(thisError+": Error in Image Output"); } try{ dLocation = dLocation + "Compressed.png";//Change to .jpg fileCon = (FileConnection)Connector.open(dLocation, Connector.READ_WRITE); if(fileCon.exists() == false){ fileCon.create(); } outputS = fileCon.openOutputStream(); outputS.write(imgData); outputS.close(); switchDisplayable(null, getTypeSelection()); }catch(IOException thisError){ switchDisplayable(null, getErrorHand()); System.err.println(thisError+": Error in Image Output"); } }
Any suggestions or links to a solution would be much appreciated. Advance thanks to those who will reply. And sorry if I posted on the wrong place.
~Rei

Reply With Quote




