6 Replies Latest reply on Mar 5, 2015 7:00 PM by bobbell

    barcode image from a servlet to a flex application

    pogla129 Level 1

      I want  to return a   barcode image from a servlet  and put it in a  image component  in  flex application ............

       

      in  the flex application  i used the code.........

       

      but  image is not showing   .............I need  some help

       

      private

       

      function resultHandler1(event:ResultEvent):void{

       

      try{

       

       

       

      var byteData1 : ByteArray=new ByteArray();

       

      var deccoder1 : Base64Decoder = new Base64Decoder();

       

       

       

      deccoder1.decode(event.result);

      byteData1 = deccoder1.toByteArray();

      imgBarcode.source=byteData1;

      }

       

       

      catch( ex : Error )

      {

      Alert.show( ex.message );

      }

      }

      try

       

       

       

       

       

      {

       

      ServletOutputStream out

       

      = response.getOutputStream();

       

      BitmapCanvasProvider canvas =

       

      new BitmapCanvasProvider(dpi, BufferedImage.TYPE_BYTE_GRAY, true, 0);

      bean.generateBarcode(canvas,

      "121212");

      canvas.finish();

      BufferedImage barcodeImage = canvas.getBufferedImage();

       

       

      //out.write(barcodeImage.toString().getBytes());

      Image ImageIO=

       

      null;

      ByteArrayOutputStream baos =

      new ByteArrayOutputStream();

      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos);

      encoder.encode(barcodeImage);

       

      out.write(baos.toByteArray());

       

       

       

      }

      catch (Exception e) {

      e.printStackTrace();

      }

      finally {

       

      }

        • 1. Re: barcode image from a servlet to a flex application
          UbuntuPenguin Level 4

          A few questions , have you debugged and checked to see if there is any data coming back ?  Is your image Base64Encoded , your code doesn't show the Java Base64 class ?

          Usually if I am going to load an image that requires request parameters instead of a source location , I use a URLLoader.

          • 2. Re: barcode image from a servlet to a flex application
            pogla129 Level 1

            Thankx  for  the reply  .  According to your queries....

            during  the  debugging some  data  found in servletOutputStream  object as

            ÿØÿà

            #B±Á RÑð$3br?

                 %&

            '()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz

            ?????????????????¢£¤¥¦§¨©ª²³´µ¶·¸¹º

            ÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÚ "

             

             

            Though  when   I  run the servlet only  then the barcode  is  desplayed in

            the browser ........but  it is  not  back  to  flex application

             

            when print  it  the  flex application it shows  like   ÿØÿà

             

            private

            function resultHandler1(event:ResultEvent):void{

             

            try{

             

            mx.controls.Alert.show( event.result.toString()); //  it  shows  ÿØÿà

            imgBarode.source=event.result;

            }

             

            Please help me with  any      kind  of solution..............

             

            • 3. Re: barcode image from a servlet to a flex application
              UbuntuPenguin Level 4

              I don't doubt that the servlet is spitting it out.  I just question where it is choking in the Flex code , and whether or not Base64 is needed since it isn't shown anywhere in the Java code ( even though that doesnt mean it isn't stored somewhere as Base64 ).

               

              Sincerely ,

                 Ubu

              • 4. Re: barcode image from a servlet to a flex application
                pogla129 Level 1

                many  many thankx  for giving me  the vital solutions................

                I  have solve  my problem according to ur direction........i have  done it  in the following way......

                 

                byte

                 

                 

                 

                [] imageBA = bb_barcode.getBytes(1, (int) bb_barcode.length());

                String s =

                new sun.misc.BASE64Encoder().encode(imageBA);

                 

                Thankx Again.........................

                • 5. Re: barcode image from a servlet to a flex application
                  UbuntuPenguin Level 4

                  I'm glad that it worked out for you.  Sometimes , these little things get in the way when going from bytes->image and vice versa

                   

                  If this response was helpful , please mark it as such.

                  • 6. Re: barcode image from a servlet to a flex application
                    bobbell

                    I am currently working on software for student attendance. I use the flex / flash and php to create the software but I faced a problem barcode scanner, can not connect to the application to call the data from the database when students scan the barcode printed on their student card. Can you help me to make the script so that it can run on flex / flash and php. it makes me crazy for a week to seek a way out …. please help me: ( thanks,