2 Replies Latest reply: Nov 20, 2010 3:10 AM by 798851 RSS

    Cannot  able  to  view  saved image

    809946
      Hi all:
      I want to save an image into the native folder of a mobile using file connection API.The application is working fine.I can see an image of .JPG form in the native folder,and the capacity keeps the same with real capacity of picture. But this picture can't be opened,error is : "No default viewer for *.JPG".
      Please help me,i'm in need of this very urgent.My code is:
      private void saveThumbImageToMobile()
      {
      try
      {
      Image newImage = Image.createImage("/sw.jpg");
      raw = getByteArray(newImage);
      }
      catch(Exception e)
      {
      e.printStackTrace();
      }
      
      try
      {
      FileConnection fc = (FileConnection) Connector.open("file:///c:/Nokia/Images/a.jpg");
      if(!fc.exists())
      {
      fc.create();
      OutputStream out;
      out = fc.openOutputStream();
      out.write(raw);
      out.flush();
      out.close();
      fc.close();
      }
      
      repaint();
      }
      catch(Exception e)
      {
      e.printStackTrace();
      }
      }
      
      public static byte[] getByteArray(Image image)
      {
      int raw[] = new int[image.getWidth() * image.getHeight()];
      image.getRGB(raw, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
      byte rawByte[] = new byte[image.getWidth() * image.getHeight() * 4];
      int n = 0;
      for(int i = 0; i < raw.length; i++)
      {
      int ARGB = raw;
      int a = (ARGB & 0xff000000) >> 24;
      int r = (ARGB & 0xff0000) >> 16;
      int g = (ARGB & 0xff00) >> 8;
      int b = ARGB & 0xff;
      rawByte[n] = (byte)b;
      rawByte[n + 1] = (byte)g;
      rawByte[n + 2] = (byte)r;
      rawByte[n + 3] = (byte)a;
      n += 4;
      }

      raw = null;
      return rawByte;
      }
      Thanks in advance.