4 Replies Latest reply on Apr 13, 2010 1:13 AM by pogla129

    Image from database....showing as black image

    pogla129 Level 1

      I am new in flex.

       

      I want  to display a flex image from database.The image is saved from flex to the server side Servlet to  oracle data base.When i retrieving the image from the data base with the help of servlet  to a flex page it shows black image .

                                                       Any one can help me  to solve the problem....................  code related to the application is given blpw

       

      From  mxml application from which I am sending the image to the servlet

       

      var

       

      dd:URLVariables=new URLVariables();

       

       

       

       

       

      var bitmapData3:BitmapData=new BitmapData(sImage3.width, sImage3.height, true, 0xffffff);

       

      var encode3:JPEGEncoder = new JPEGEncoder(100);

       

      var ping3:ByteArray = encode3.encode(bitmapData3);

       

      var be3:Base64Encoder = new Base64Encoder();

      be3.encodeBytes(ping3);

       

      var jpegToStrg:String=new String();

      jpegToStrg = be3.flush().toString();

      dd.pictr=jpegToStrg;

       

       

      var request:URLRequest = new URLRequest("http://"+pop.Url()+"/ProjectNew/FirmRegistrationServlet");

       

      request.method=URLRequestMethod.POST;

      request.data = dd;

       

      In the  servlet file where image is saved to data base

       

       

       

       

      byte[] image1 = new byte[42015];

      image1 = request.getParameter(

      "pic").getBytes();

       

      tsql

       

      = "INSERT INTO PERNEWADMIN.spon_firm (SPON_FIRM_CD,SPON_FIRM_NAME,ADDR1, ";

       

      tsql += " AUTH_SIGNATURE1_IMAGE,

       

      tsql += " ) VALUES(?,?,?,?,?,)";

       

      ps = tcon.prepareStatement(tsql);

       

      ps.setString(1, firm_cd);

       

      ps.setString(2, SF.getSpon_firm_name());

       

      ps.setString(3, SF.getAddr1());

       

      ps.setBytes(12, image1 )   ///Here is the image variable

      ps.execute();

       

      Image is saved successfully

       

      Given blow the the servlet from where  i want to select the image.............

       

      out.print("<?xml version=\"1.0\"?>\n");

       

      out.print("<table>");

      out.print("<image>");

      Blob blobSign1 =

      null;

      tsql

       

      = "SELECT auth_signature1_image,auth_signature2_image,auth_signature3_image FROM pernewadmin.spon_firm ";

       

      tsql += " WHERE spon_firm_name LIKE 'hhh' ";

       

      ps = tcon.prepareStatement(tsql);

       

      // ps.setString(1, fname);

       

       

      rs = ps.executeQuery();

       

      while (rs.next()) {

      blobSign1 =

      rs.getBlob("auth_signature1_image");

      }

       

      int length = (int) blobSign1.length();

       

      byte[] buffer = new byte[length];

      BufferedInputStream bis =

      null;

      bis =

      new BufferedInputStream(blobSign1.getBinaryStream());

       

      while ((length = bis.read(buffer)) != -1) {

       

      out.write(buffer, 0, length);

       

      }

       

      out.print("</image>");

       

      out.print("</table>");

       

       

      Given below the mxml page where i want show the image

       

       

      private function resultGetFirmDetails(event:ResultEvent):void{

       

      try{

       

      var xmldata1:XML=event.result as XML;

       

      var byteData : ByteArray=new ByteArray();

       

      var deccoder : Base64Decoder = new Base64Decoder();

      deccoder.decode(xmldata1.image);

      byteData = deccoder.toByteArray();

      sImage1.visible=

      true;

      sImage1.source=byteData; // here a black image is displayed  

       

       

      }

       

      catch( ex : Error )

      {

      Alert.show(

      "Error:In .xmnl file" );

      }

      }