How to load and display a byte array (jpeg) image file dynamically in Flex?

My web service client (servlet) received a binary jpeg data from an Image Server. The Flex application invokes the
servlet via HttpService and receives the binary jpeg data as byte array.  How could it be displayed dynamically
without writing the byte array to a jpeg file?  Please help (some sample code is very much appreciated).

JPEGEncoder is only useful for converting BitmapData to ByteArray, not the other way around.
By the way JPEGEncoder and PNGEncoder are part of the Flex SDK now, so no need to use AS3Lib (alltough it's a good library to have around).
To display/use a ByteArray as image, use a Loader instance with the loadBytes method.
    Loader.loadBytes(bytes:ByteArray, context:LoaderContext = null);
Listen for the complete event on the Loader.contentLoaderInfo and get the BitmapData in the event handler.
private function loadJpeg():void {
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
    //jpgBA is the ByteArray loaded from webservice
    loader.loadBytes(jpgBA);
private function loaderCompleteHandler(evt:Event):void {
    var t:LoaderInfo = evt.currentTarget as LoaderInfo;
    // display the jpeg in an Image component
    img.source = t.content;
<mx:Image id="img" scaleContent="false" />

Similar Messages

  • How to load and display the external flv video files in dynamicly and the how to control the flv fil

    How to load and display the external flv video files in dynamicly using AS 3.0
    and  How to control the flv file  add the play paus button and add seekbar.
    I have using to load the flv file following code
    var flvPlaceHolder1:MovieClip = new MovieClip();
    var vid1:Video = new Video(734, 408);
    flvPlaceHolder1.addChild(vid1);
    addChild(flvPlaceHolder1);
    flvPlaceHolder1.x = 1059;
    flvPlaceHolder1.y = 152;
    var nc1:NetConnection = new NetConnection();
    nc1.connect(null);
    var ns1:NetStream = new NetStream(nc1);
    vid1.attachNetStream(ns1);
    var listener1:Object = new Object();
    listener1.onMetaData = function(evt:Object):void {};
    ns1.client = listener1;
    ns1.play("GV-1600 TURNING.flv");
    ns1.addEventListener(NetStatusEvent.NET_STATUS, statusChanged1);
    function statusChanged1(ns1:NetStatusEvent):void
             trace(ns1.info.code);
            if (ns1.info.code == 'NetStream.Buffer.Empty')
                 trace('the video has ended');
                 removeChild(flvPlaceHolder1);
                 //trace('removeChild');
                gotoAndPlay(1786);
    then how to add the play,paus ,full screen button    and   seekbar,volumebar.

    I have to Create the flash presentation for our company product
    In this presentation the left  side the text animation are displayed then right side the our product video is displayed.
    In this presentation i need the following option :
    1, The first product video and animation is finished then the next product is played
    2, then the video displayed  (size width and height 400x300) , I click this video to increase the size(ex:1000x700)
    3, then the playing video i control  it play, stop, paus button and volume bar, seek bar.
    4, then this presentation is displayed on 42 inches LCD TV so this full presentation is run full screen.
    I have finished first two steps 1 and 2
    the following are the screen short and code:-
    code :-
    var count=0;
    var flvPlaceHolder2:MovieClip = new MovieClip();   
    var vid2:Video = new Video(734, 408);
    flvPlaceHolder2.addChild(vid2);
    addChild(flvPlaceHolder2);
    flvPlaceHolder2.x = 1059;
    flvPlaceHolder2.y = 152;
    var nc2:NetConnection = new NetConnection();
    nc2.connect(null);
    var ns2:NetStream = new NetStream(nc2);
    vid2.attachNetStream(ns2);
    var listener2:Object = new Object();
    listener2.onMetaData = function(evt:Object):void {};
    ns2.client = listener2;
    ns2.play("GS-4000.flv");
    this.addEventListener(Event.ENTER_FRAME, BtnFadeIn2);
    function BtnFadeIn2(event:Event):void
        if (this.currentFrame == 387)
            /*flvPlaceHolder2.x = 30;
            flvPlaceHolder2.y = 140;
            vid2.width=1800;
            vid2.height=800;
            trace('Screen size is changed');*/
            if(count==0)
            flvPlaceHolder2.x = 30;
            flvPlaceHolder2.y = 140;
            vid2.width=1800;
            vid2.height=800;
            count++;
    ns2.addEventListener(NetStatusEvent.NET_STATUS, statusChanged2);
    function statusChanged2(ns2:NetStatusEvent):void
        trace(ns2.info.code);
        if (ns2.info.code == 'NetStream.Buffer.Empty')
                trace('the video has ended');
                 removeChild(flvPlaceHolder2);
                 //trace('removeChild');
                gotoAndPlay(433);
    flvPlaceHolder2.buttonMode=true;
    flvPlaceHolder2.addEventListener(MouseEvent.CLICK,home2);
    function home2(e:MouseEvent):void
        if(vid2.width==734 && vid2.height==408)
            flvPlaceHolder2.x = 30;
            flvPlaceHolder2.y = 140;
            vid2.width=1800;
            vid2.height=800;
        else
            flvPlaceHolder2.x = 1059;
            flvPlaceHolder2.y = 152;
            vid2.width=734;
            vid2.height=408;

  • How to load and unload more than one external swf files in different frames?

    I do not have much experience on Adobe Flash or Action Script 3, but I know the basics.
    I am Arabic language teacher, and I design an application to teach Arabic, I just would like to learn how to load and unload more than one external swf files in different frames.
    Thanks

    Look into using the Loader class to load the swf files.  If you want to have it happen in different frames then you can put the code into the different frames.

  • How to change the image into byte and byte array into image

    now i am developing one project. i want change the image into byte array and then byte array into image.

    FileInputStream is = new FileInputStream(file);
    byte[] result = IOUtils.toByteArray(is);
    with apache common IO lib

  • How to load and unload Multiple External SWF

    hello there,
    i need help to figuring out how to load and also unload(removing) multiple external SWF.
    so here is what i;m trying to do,
    i want to load multiple external SWF and play it on my main SWF now i hove no problem with just loading multiple SWF and placing it in the display list .The problem came up when i tried removing those loaded SWF from the display list ,The problem exist because i have no way to refer to what i have loaded and placed on the display list,
    i used a single loader instance to load all that external swf,
    i do know that we have to remove all the event listener related to the external SWF that we want to remove and for this purpose i have crated a function called destroy which the main objective for this function is to remove all event listener inside the swf and also isolating all variable so it would be eligible for garbage collecting, here is what the code look like:
    // Create this in every object you use
    public function destroy():void
         // Remove event listeners
         // Remove anything in the display list
         // Clear the references to other objects, so it gets totally isolated
    sorry it just a kind of pseudocode cause this function will customize with it's own property i did this just for the purpose of simplicity and easy understanding..,
    so now back to main problem how should i solve this problem??
    i tried used an arraf to save all the loaded swf
         the array is just used to save the what the loader is loading but the adding to display method is using
    movieClipActAsContainer.addChild(e.target.content); //the event is from the Event.COMPLETE
    but i have a hard time using that arrya back and matching it to the one i got from the display list.
    please do help me,
    any suggestion would be greatly appreciated,
    and if can pleas show me a source code or pseudocode of what you're suggesting to me cause my english is not so fluent yet,
    thanks before.

    Hey EI,
    I had done this kind of project recently and for loading and unloading different swfs. I had used loaders specific to that filename and for removing I had used a single movieclip instance name and on clicking that specific loader request name that needs to be removed will be requested from the specific function. As mentioned below
    Loading SWF:
    ===============================
    swfLoaderIndia.load(swfRequestIndia);//This will load the request
    If you are inside a movieclip while requesting use below code
    MovieClip(this.root).addChild(swfLoaderIndia);//This will load swf on stage
    or else
    Stage.addChild(swfLoaderIndia);
    Unloading SWF
    =====================================
    If you are inside a movieclip while requesting use below code
    MovieClip(this.root).removeChild(swfLoaderIndia);//This will unload swf on stage
    or else
    Stage.removeChild(swfLoaderIndia);
    Above code will be in specific function which will be requested when the loading and unloading is required.
    I hope this helps you in your project.
    With Regards,
    Sagar S. Ranpise

  • How to Generate and Display SVG Graphics in ABAP

    Hi everybody,
    I tried to complete the Tutorial "How to Generate and Display SVG Graphics in ABAP, Part 1" by Siarhei Ulasenka (https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/ad83a990-0201-0010-d680-a189f8bc20fa).
    Unfortunately when I tried the example to display an SVG Drawing in an ABAP Report I get the error message "Es ist ein Laufzeitfehler aufgetreten, ungültiges Zeichen" (english should be something like "Runtime Error, unkown character"). But it works when I open the svgfile in a new IE Window (parameter in_place from cl_gui_html_viewer->show_url). Also when I open a svg file from the local disc it works fine.
    The code:
        CALL METHOD html_control->load_data
          EXPORTING
            url            = 'chart.svg'
            type         = 'image'
            subtype    = 'svg+xml'
          CHANGING
            data_table = lt_svg
          EXCEPTIONS
            OTHERS     = 1.
        CALL METHOD html_control->show_url
          EXPORTING
            url        = 'chart.svg'
            in_place   = 'X'
          EXCEPTIONS
            cntl_error = 1.
    Has anyone a solution? Thanks in advance for your help!
    Regards
    Kathrin

    Hello Alex,
    The Corel SVG viewer has problems loading and displaying the examples (see the list of limitations at their site). Try to use the Adobe viewer instead.
    Regards,
    Sergei Ulasenka

  • Need to send and receive larger byte array

    I have a small WCF service, self hosted in a console app. On the same computer I have a client application. Both are running in the debugger in VS2008. The proxy code and the config file were generatred from the running service using svcutil.
    In one of the service calls, the service reads a pdf file and sends the contents as a byte array. The client receives the byte array, saves it as a pdf file, and displays it.
    Everything is fine for all other kinds of calls, and this one works fine also as long as the file is small (say 14K). But if the file is larger (say 84K), the client crashes (VHOST has stopped working).
    Is there some kind of setting that will allow me to send and receive larger byte arrays (> 100 K)?
    Thanks,
    Jon Jacobs
    In transmission, subatomic particles managed by professionals.
    No innocent electrons were harmed.

    Hi Jon,
    You'll want something like this to increase the message size quotas:
    <bindings>
    <basicHttpBinding>
    <binding name="basicHttp" allowCookies="true"
    maxReceivedMessageSize="20000000"
    maxBufferSize="20000000"
    maxBufferPoolSize="20000000">
    <readerQuotas maxDepth="32"
    maxArrayLength="200000000"
    maxStringContentLength="200000000"/>
    </binding>
    </basicHttpBinding>
    </bindings>
    The justification for the values is simple, they are sufficiently large to accommodate most messages. You can tune that number to fit your needs. The low default value is basically there to prevent DOS type attacks. Making it 20000000 would allow for a distributed
    DOS attack to be effective, the default size of 64k would require a very large number of clients to overpower most servers these days.
    If you're still getting this error message while using the WCF Test Client, it's because the client has a separate MaxBufferSize setting.
    To correct the issue:
    Right-Click on the Config File node at the bottom of the tree
    Select Edit with SvcConfigEditor
    A list of editable settings will appear, including MaxBufferSize.
    Note: Auto-generated proxy clients also set MaxBufferSize to 65536 by default.
    Let me know if this helped.
    Regards,
    Raghu

  • How to add byte[] array based Image to the SQL Server without using parameter

    how to add byte[] array based Image to the SQL Server without using parameter.I have a column in table with the type image in sql and i want to add image array to the sql image column like below:
    I want to add image (RESIM) to the procedur like shown above but sql accepts byte[] RESIMI like System.Drowing. I whant that  sql accepts byte [] array like sql  image type
    not using cmd.ParametersAdd() method
    here is Isle() method content

    SQL Server binary constants use a hexadecimal format:
    https://msdn.microsoft.com/en-us/library/ms179899.aspx
    You'll have to build that string from a byte array yourself:
    byte[] bytes = ...
    StringBuilder builder = new StringBuilder("0x", 2 + bytes.Length * 2);
    foreach (var b in bytes)
    builder.Append(b.ToString("X2"));
    string binhex = builder.ToString();
    That said, what you're trying to do - not using parameters - is the wrong thing to do. Not only it is insecure due to the risk of SQL injection but in the case of binary data is also inefficient since these hex strings are larger than the original byte[]
    data.

  • Loading And Displaying image From MYSQL

    Hello, How can I load and display picture stored into a MYSQL database in a Swing GUI using for example JLable component.

    establish a connection to ur sql, n
    retireve the record with the images or image url in the db.
    and then load it to a Image icon and set it to a JLabel.

  • How to acces and display datas storaged in cache for a SUP 2.0 workflow?

    HI to all.
    I have an application with a item menu which obtains data thought a online request. the result is shown is a listview.
    My problem is when my BlackBerry has no conection ( offline scenario). When I select the menu item, I obtain an error.
    How to acces and display datas storaged in cache for my MBO? I have read that I can use getMessageValueCollection in custom.js to access to my datas but once I get the datas, How can associate those datas to a Listview like a online request?? Do i have to develop my own screen in html or how?
    Thanks.

    I'm not entirely clear on what you mean by "cache" in this context.  I'm going to assume that what you are really referring to is the contents of the workflow message, so correct me if I'm wrong.  There is, in later releases, the ability to set an device-side request cache time so that if you issue an online request it'll store the results in an on-device cache and if you subsequently reissue the same online request with the same parameter values within that timeout period it'll get the data from the cache rather than going to the server, but my gut instinct is that this is not what you are referring to.
    To access the data in the workflow message, you are correct, you would call getMessageValueCollection().  It will return an object hierarchy with objects defined in WorkflowMessage.js.  Note that if your online request fails, the data won't magically appear in your workflow message.
    To use the data in the workflow message to update a listview, feel free to examine the code in the listview widgets and in API.js.  You can also create a custom listview as follows:
    function customBeforeNavigateForward(screenKey, destScreenKey) {
         // In this example, we only want to replace the listview on the "My Approvals" screen    
         if (destScreenKey == 'My_Approvals'){
              // First, we get the MessageValueCollection that we are currently operating on
              var message = getCurrentMessageValueCollection();
              // Next, we'll get the list MessageValue from that MessageValueCollection
              var itemList = message.getData("LeaveApprovalItem3");
              // Because its a list, the Value of the MessageValue will be an array
              var items = itemList.getValue();
              // Figure out how many items are in the list
              var numOfItems = items.length;
              // Iterate through the results and build our list
              var i = 0;
              var htmlOutput = '<div><ul data-role="listview" data-theme="k" data-filter="true">';
              var firstChar = '';
              while ( i < numOfItems ){
                   // Get the current item. This will be a MessageValueCollection.
                   var currItem= items<i>;
                   // Get the properties of the current item.
                   var owner = currItem.getData("LeaveApprovalItem_owner_attribKey").getValue();
                   var type = currItem.getData("LeaveApprovalItem_itemType_attribKey").getValue();
                   var status = currItem.getData("LeaveApprovalItem_itemStatus_attribKey").getValue();
                   var startDate = currItem.getData("LeaveApprovalItem_startDate_attribKey").getValue();
                   var endDate = currItem.getData("LeaveApprovalItem_endDate_attribKey").getValue();
                   // Format the data in a specific presentation
                   var formatStartDate = Date.parse(startDate).toString('MMM/d/yyyy');
                   var formatEndDate = Date.parse(endDate).toString('MMM/d/yyyy');
                   // Decide which thumbnail image to use
                   var imageToUse = ''
                        if (status == 'Pending'){
                             imageToUse = 'pending.png';
                        else if (status == 'Rejected'){
                             imageToUse = 'rejected.png';
                        else {
                             imageToUse = 'approved.png';
                   // Add a new line to the listview for this item
                   htmlOutput += '<li><a id ="' + currItem.getKey() + '" class="listClick">';
                   htmlOutput += '<img src="./images/' + imageToUse + '" class="ui-li-thumb">';
                   htmlOutput += '<h3 class = "listTitle">' + type;
                   htmlOutput +=  ' ( ' + owner + ' ) ';
                   htmlOutput += '</h3>';
                   htmlOutput += '<p>' + formatStartDate + ' : ' + formatEndDate + '</p>';
                   htmlOutput += '</a></li>';
                   i++;
              htmlOutput += '</ul></div>';
              // Remove the old listview and add in the new one.  Note: this is suboptimal and should be fixed if you want to use it in production.
              $('#My_ApprovalsForm').children().eq(2).hide();
              $('#My_ApprovalsForm').children().eq(1).after(htmlOutput);
              // Add in a handler so that when a line is clicked on, it'll go to the right details screen
              $(".listClick").click(function(){
                   currListDivID = $(this).parent().parent();
                   $(this).parent().parent().addClass("ui-btn-active");
                   navigateForward("Request_Details",  this.id );
                   if (isBlackBerry()) {
                        return;
         // All done.
         return true;

  • PDF addresses not longer load and display PDF in Firefox and solutions suggest to other users with problem DON'T WORK (work fine in Chrome and Safari)

    This is an ongoing problem with other users. When putting a PDF in address window of Firefox and clicking go to address FIREFOX WILL NOT LOAD AND DISPLAY THE PDF. This problem has come up in questions from other users on your site. NONE OF THE SUGGESTED SOLUTIONS WORK! (trying either the Firefox PDF viewer or the Acrobat viewer as default viewer)
    I am using Firefox 23.0.1 (as some of the other users with the same problem). This was not a problem in the past with Firefox. Safari and Chrome continue load and display PDFs just fine from their addresses. This is a big problem as I now have to inform people who want to view my PDFs NOT TO USE FIREFOX BUT TO USE SAFARI OR CHROME.

    It appears that a link to a PDF on an internet page will not download in Firefox either!
    I went to this page:
    http://www.nasa.gov/connect/ebooks/earth_art_detail.html#.UjYEzrwsU08
    and tried to download the PDF link at the bottom of the page (Download: PDF 11.3 MB) It didn't work! Nothing happens. Tried it in Safari and it worked flawlessly.
    I have a PDF file of my work in the public_html folder on my URL. I give the address generated by that file to people who want to view my work---this works perfectly in Safari and Chrome. As to your other question, can't bookmark it if I can't get to it in Firefox.

  • How to place an image in database and how to retrieve and display it in the front end

    how to place an image in database and how to retrieve and display it in the front end
    and to place an image in database and retrieve the image from database using xml
    please,help me out.

    Create a table with a Long RAW Datatype column for storing the Image Column Data.
    Create the form based on the table , which by defaults the column with LONG RAW atatype to a Image Item.
    You can use Forms Built in function READ_IMAGE_FILE to read a Image file stored on the file system in to the image item.
    A save on the form saves the image in the Image item in the long raw column.

  • How to get and display current year

    hi,
    how to get and display current year
    and need it to convert numeric format if it is orginally
    in character format.

    Hi,
    chk this FM.
    CALL FUNCTION 'GET_CURRENT_YEAR'
      EXPORTING
        BUKRS         = '1000'     " Company Code
        DATE          = SY-DATUM   " Date to find fiscal year for
      IMPORTING
        CURRM         = w_currm    " Current Fiscal Month
        CURRY         = w_curry    " Current Fiscal Year
        PREVM         = w_prevm    " Previous Fiscal Month
        PREVY         = w_prevy.   " Previous Fiscal Year
    rgds
    anver
    if hlped pls mark points

  • HT1600 I get the menu and can pick a movie but then it won't load and displays an error message

    I get the menu and can pick a movie but then it won't load and displays an error

    What version of iPhoto do you have installed?  Is if one of the versions shown as not compatible in this screenshot?
    If it is then go to the App Store and download iPhoto 9.5.  It will be free if you have an iPhoto 9 or later verson currently.
    OT

  • Load and display image using CDC

    Hi everyone,
    Please help. I'm new to java. I need a simple routine to load and display an image from the file system into a CDC app on windows mobile 5. I'm usin creme 4.1.
    Thanx in advance

    Use the following as a guide:
    1. Get the image (path below must be absolute):
    public static Image getImage(String filename) throws ScanException {
    Image img = null;
    // Read paths from properties file
    StringBuffer buf = new StringBuffer("\\");
    buf.append(ScanUtility.getPathImages());
    buf.append("\\");
    buf.append(filename);
    buf.append(".jpg");
    File dataFile = new File(buf.toString());
    if(!dataFile.exists())
    throw new ScanException("Cannot locate the file:\n" + dataFile.getAbsolutePath());
    img = Toolkit.getDefaultToolkit().createImage(buf.toString());
    return img;
    2. Create a class to display the image (pass in the image, above):
    ImagePanel class source:
    import java.awt.*;
    import java.awt.image.*;
    public class ImagePanel extends Panel {
    private Image image = null;
    private Image scaledImage = null;
    private boolean imageComplete = false;
    public ImagePanel(Image img) {
    image = img;
    scaledImage = image.getScaledInstance(200, -1, Image.SCALE_DEFAULT);
    prepareImage(scaledImage, this);
    // Override the paint method, to render the image
    public void paint(Graphics g) {
    if(imageComplete) {
    g.drawImage(scaledImage, 0, 0, this);
    // Override imageUpdate method, to prevent repaint() from trying
    // to do anything until the image is scaled
    public boolean imageUpdate(Image img, int infoFlags, int x, int y, int w, int h) {
    if(infoFlags == ImageObserver.ALLBITS) {
    imageComplete = true;
    repaint();
    return super.imageUpdate(img, infoFlags, x, y, w, h);
    public void flush() {
    image.flush();
    scaledImage.flush();
    image = null;
    scaledImage = null;
    }

Maybe you are looking for

  • Does Time Machine overwrite files stored as network storage

    I am planning to use my new 1 TB Time Capsule as a NAS as well as a location for my Time Machine backups. Will the files (like movies) that I store on the Time Capsule be overwritten when Time Machine runs out of room for backups? I read that it was

  • "Send" email option disappeared BB8520

    I followed your steps (deleteing service books and then sending them again), rebooted, etc. Nothing works. I called my carrier, they don't have a clue. help please!! THANKS

  • Error 1906, 1603,1628

    I tried to update my iTunes software and I received the error message 1906: C://Windows\Installer\ae8c8c.msi Error - 2147286775. I tried to reupdate the software after turning off my antivirus software and I received Error 1603. So I restarted my com

  • Is 10.1.102.64 the really last version of flash player?

    i have installed flash player version 10,2,161,23 but the adobe test page http://kb2.adobe.com/cps/155/tn_15507.html#main_LatestFlashPlayer tells me to install as 'latest vesion' 10.1.102.64 i do not understand that. could somebody please help me? me

  • 9300 internet is not working at all.

    My internet and bbm and apps that use internet were working perfectly fine and I've had the phone for nearly 2 years, but a couple of days ago they just stopped working. I can text and ring like normal but my internet isn't working. I've switched on