Help! Saving an image to stream and recreating it on client over network

Hi,
I have an application that uses JDK 1.1.8. I am trying to capture the UI screens of this application over network to a client (another Java app running on a PC). The client uses JDK 1.3.0. As AWT image is not serializable, I got code that converts UI screens to int[] and persist to client socket as objectoutputstream.writeObject and read the data on client side using ObjectInputStream.readObject() api. Then I am converting the int[] to an Image. Then saving the image as JPEG file using JPEG encoder codec of JDK 1.3.0.
I found the image in black and white even though the UI screens are in color. I have the code below. I am sure JPEG encoder part is not doing that. I am missing something when recreating an image. Could be colormodel or the way I create an image on the client side. I am testing this code on a Win XP box with both server and client running on the same machine. In real scenario, the UI runs on an embedded system with pSOS with pretty limited flash space. I am giving below my code.
I appreciate any help or pointers.
Thanks
Puri
     public static String getImageDataHeader(Image img, String sImageName)
         final String HEADER = "{0} {1}x{2} {3}";
         String params[] = {sImageName,
                            String.valueOf(img.getWidth(null)),
                            String.valueOf(img.getHeight(null)),
                            System.getProperty("os.name")
         return MessageFormat.format(HEADER, params);
     public static int[] convertImageToIntArray(Image img)
         if (img == null)
             return null;
        int imgResult[] = null;
        try
            int nImgWidth = img.getWidth(null);
            int nImgHeight = img.getHeight(null);
            if (nImgWidth < 0 || nImgHeight < 0)
                Trace.traceError("Image is not ready");
                return null;
            Trace.traceInfo("Image size: " + nImgWidth + "x" + nImgHeight);
            imgResult = new int[nImgWidth*nImgHeight];
            PixelGrabber grabber = new PixelGrabber(img, 0, 0, nImgWidth, nImgHeight, imgResult, 0, nImgWidth);
            grabber.grabPixels();
            ColorModel model = grabber.getColorModel();
            if (null != model)
                Trace.traceInfo("Color model is " + model);
                int nRMask, nGMask, nBMask, nAMask;
                nRMask = model.getRed(0xFFFFFFFF);
                nGMask = model.getRed(0xFFFFFFFF);
                nBMask = model.getRed(0xFFFFFFFF);
                nAMask = model.getRed(0xFFFFFFFF);
                Trace.traceInfo("The Red mask: " + Integer.toHexString(nRMask) + ", Green mask: " +
                                Integer.toHexString(nGMask) + ", Blue mask: " +
                                Integer.toHexString(nBMask) + ", Alpha mask: " +
                                Integer.toHexString(nAMask));
            if ((grabber.getStatus() & ImageObserver.ABORT) != 0)
                Trace.traceError("Unable to grab pixels from the image");
                imgResult = null;
        catch(Throwable error)
            error.printStackTrace();
        return imgResult;
     public static Image convertIntArrayToImage(Component comp, int imgData[], int nWidth, int nHeight)
         if (imgData == null || imgData.length <= 0 || nWidth <= 0 || nHeight <= 0)
             return null;
        //ColorModel cm = new DirectColorModel(32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);
        ColorModel cm = ColorModel.getRGBdefault();
        MemoryImageSource imgSource = new MemoryImageSource(nWidth, nHeight, cm, imgData, 0, nWidth);
        //MemoryImageSource imgSource = new MemoryImageSource(nWidth, nHeight, imgData, 0, nWidth);
        Image imgDummy = Toolkit.getDefaultToolkit().createImage(imgSource);
        Image imgResult = comp.createImage(nWidth, nHeight);
        Graphics gc = imgResult.getGraphics();
        if (null != gc)
            gc.drawImage(imgDummy, 0, 0, nWidth, nHeight, null);       
            gc.dispose();
            gc = null;       
         return imgResult;
     public static boolean saveImageToStream(OutputStream out, Image img, String sImageName)
         boolean bResult = true;
         try
             ObjectOutputStream objOut = new ObjectOutputStream(out);
            int imageData[] = convertImageToIntArray(img);
            if (null != imageData)
                // Now that our image is ready, write it to server
                String sHeader = getImageDataHeader(img, sImageName);
                objOut.writeObject(sHeader);
                objOut.writeObject(imageData);
                imageData = null;
             else
                 bResult = false;
            objOut.flush();                
         catch(IOException error)
             error.printStackTrace();
             bResult = false;
         return bResult;
     public static Image readImageFromStream(InputStream in, Component comp, StringBuffer sbImageName)
         Image imgResult = null;
         try
             ObjectInputStream objIn = new ObjectInputStream(in);
             Object objData;
             objData = objIn.readObject();
             String sImageName, sSource;
             int nWidth, nHeight;
             if (objData instanceof String)
                 String sData = (String) objData;
                 int nIndex = sData.indexOf(' ');
                 sImageName = sData.substring(0, nIndex);
                 sData = sData.substring(nIndex+1);
                 nIndex = sData.indexOf('x');
                 nWidth = Math.atoi(sData.substring(0, nIndex));
                 sData = sData.substring(nIndex+1);
                 nIndex = sData.indexOf(' ');
                 nHeight = Math.atoi(sData.substring(0, nIndex));
                 sSource = sData.substring(nIndex+1);
                 Trace.traceInfo("Name: " + sImageName + ", Width: " + nWidth + ", Height: " + nHeight + ", Source: " + sSource);
                 objData = objIn.readObject();
                 if (objData instanceof int[])
                     int imgData[] = (int[]) objData;
                     imgResult = convertIntArrayToImage(comp, imgData, nWidth, nHeight);
                     sbImageName.setLength(0);
                     sbImageName.append(sImageName);
        catch(Exception error)
            error.printStackTrace();
         return imgResult;
     }   

While testing more, I found that the client side is generating color UI screens if I use JDK 1.3 JVM for running the server (i.e the side that generates the img) without changing single line of code. But if I use JDK 1.1.8 JVM for the server, the client side is generating black and white versions (aka gray toned) of UI screens. So I added code to save int array that I got from PixelGrabber to a text file with 8 ints for each line in hex format. Generated these files on server side with JVM 1.1.8 and JVM 1.3. What I found is that the 1.1.8 pixel grabber is setting R,G,B components to same value where as 1.3 version is setting them to different values thus resulting in colored UI screens. I don't know why.

Similar Messages

  • Saved an image as library and now all in iphoto images disappeared

    I was saving an image from email to iphoto, and somehow it was saved as my iphoto library. All of my photos are now gone, there were hundreds, and the one image I just saved is just there. Where are my photos??? Don't they get saved somewhere on my hard drive aside from being hosted iphoto. I have a MAC AIr and iPhoto '11.

    Rename it back.
    (110127)

  • Help getting an image to scale and move?

    I have a still image in the timeline and I select it to load it back in the Source Window.
    - On the first frame I select the Position and Scale watch icons.
    - I then click to add a keyframe for both Position and Scale.
    - I drag the Playhead to the last frame
    - I add a keyframe for both Position and Scale on the last frame
    - I scale the image down on the last frame
    - I change it position by typing in a new coordinate
    However, when I drag through the clip with the Playhead nothing happens. What am I doing wrong?
    Thanks.

    The first one is easy enough. You are not looking in the right place. It isn't in the sequence, they are on the timeline in the Effect Controls panel.
    You need to look in the Effect Controls panel - see the red circles around the keyframes. If your panel does not show the images timeline in the Effect Controls panel, the second image shows you the arrow to click on.
    You might want to try putting the keyframes a bit in from the beginning and a bit in from the end. That way you can see the keyframes easier. Once set the way you want them, you can select the keyframes and move the to the beginning or the end as required. Do this just so you can see the keyframes easier at first. Warning, you might want to zoom all the way in at the beginning and the end to make sure the keyframe is at the beginning or the end. Sometimes dragging it does not get it all the way there.
    Your second issue is possibly more complicated. If you set the motion parameters before you click on the stopwatches, and you do not change anything after setting the stopwatches, then you must  manually set a keyframe for each
    If you set the stopwatches, then change the settings (both of them), the keyframes are placed for you. Once you move the CTI, if you change either motion setting, new keyframes will appear.
    Let me know if this helps. Otherwise I will be more specific with my next tutorial.

  • Help - Best router for netflix streaming and gaming

    Hello,
    My choices are Airport Extreme, Linksys WRT610N, dlink DIR-825
    Has anyone tried these?
    Thanks for your help.
    Frank

    If online gaming is the most important requirement, you will want to go with routers that support UPnP. All the major game console vendors support sites list compatible routers for their respective versions of online gaming access.
    For streaming you will want a router with both Gigabit Ethernet (WAN & LAN-side) and offers 802.11n that operates in the 5 GHz radio band with wide-channels.
    Finally, if you want to support both gaming and streaming at the same time, I suggest that you look at routers that can operate in both the 2.4 & 5 GHz bands simultaneously.

  • Best way to store and access all my media over network?

    With nearly 500GBs of music, movies and TV in my iTunes library, my G5's hard drive is just about full. And since I tend to watch everything on my significantly faster Macbook Pro via Front Row, it means I have to keep my G5 up and running all the time. Which feels like a huge waste of energy.
    So... what's the most efficient way to store and access my media? Here are some ideas off the top of my head. If anyone has any better ideas, please share...
    IDEA 1: BUY A TERABYTE EXTERNAL DRIVE AND CONNECT TO MY AIRPORT EXTREME'S USB PORT.
    Pros...
    1.) No need to keep my G5 up and running all the time, just the router and the external drive connected to it.
    2.) All media stored in one iTunes library which can be accessed by any wireless Mac on my network.
    Cons...
    1.) I have no idea if this would even work.
    2.) Would the USB connection be fast enough to play HD content?
    3.) Would the Extreme's b/g signal be fast enough?
    4.) Would my Macs even recognize an iTunes Library on a USB hard drive connected to my Airport Extreme with no OS of its own?
    5.) Even if it were fast enough, could two separate Macs share the same iTunes library?
    6.) I'd have to lose my wireless printer, which currently occupies the single USB port in my Airport.
    IDEA 2: BUY AN APPLE TIME CAPSULE AND USE ITS INTERNAL DRIVE AS MY ITUNES LIBRARY
    Pros...
    1.) The internal SATA drive will certainly be faster than any external USB drive.
    2.) Get to keep my USB port for wireless printing.
    Cons...
    1.) Still don't know if it would work.
    2.) Would not be able to take advantage of faster 802.11(n) speed, as my G5 tower is b/g only.
    3.) Pricey. $500 for a Time Capsule seems excessive not being able to take advantage of n speed boost.
    IDEA 3: BUY AN APPLE TV
    Pros...
    1.) I could watch HD content on my beautiful 30 inch Apple Cinema Display!
    2.) I could access all my content wirelessly through my network.
    3.) I get to keep my wireless printer wireless.
    Cons...
    1.) I don't own a TV.
    2.) I don't know if Apple TV will even play on my 30 inch Apple Cinema Display.
    3.) I don't know if my Macbook Pro will play files from Apple TV.
    4.) Apple TV doesn't come with a Terabyte hard drive.
    5.) I'm not sure I really understand what Apple TV is. (With a 30 inch Cinema Display, doesn't buying a TV seem redundant?)
    IDEA 4: SELL MY G5, BUY A TIME CAPSULE, AND HOPE NO ONE EVER STEALS MY MACBOOK PRO.
    Pros...
    1.) Can take advantage of that speedy wireless (n) network.
    Cons...
    1.) Still don't know if a wireless iTunes library stored on a router would work.
    2.) What will I do with my 30 inch Apple cinema display?
    3.) No backup computer if something ever goes wrong.

    Perfectly possible:
    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    Back up to the 2TB drie:
    Most Simple Back Up:
    Drag the iPhoto Library from your Pictures Folder to another Disk. This will make a copy on that disk.
    Slightly more complex: Use an app that will do incremental back ups. This is a very good way to work. The first time you run the back up the app will make a complete copy of the Library. Thereafter it will update the back up with the changes you have made. That makes subsequent back ups much faster. Many of these apps also have scheduling capabilities: So set it up and it will do the back up automatically.
    Example of such apps: Chronosync - but there are many others. Search on MacUpdate or the App Store
    Regards
    TD

  • Crashing in PS CS and Quark when opening files over network

    Mac Pro and MacBook Pro 10.4.8 using Adobe Photoshop CS2 and Quark 6.52 will crash or become VERY unstable when opening files from server or remote machine. Server is 10.3.9 or remote Mac running 10.4.7, all works fine IF file are copied to client machine, but cannot use -File/Open dialog. This is a network isue in relation to Intel translation, is there a fix (Rosetta?)

    Try looking for some "special" characters in file or folder names ( e.g. / or ?).
    I had similar problems with PPC-Apps (InDesign CS2 and 4D Client 2003) since 10.4.7 and 10.4.8. App crashes or shows strange grey boxes on the screen when I tried to open files over the network, no probs with same files locally.
    MacBook Pro   Mac OS X (10.4.8)  

  • Saving image in windows 8.1 using stream and bitmap encoder id

    Hi
    var renderTargetBitmap = new RenderTargetBitmap();
    await renderTargetBitmap.Render(myElementTree);
    var pixels = await renderTargetBitmap.GetPixelsAsync();
    var picker = new FileSavePicker();
    // Picker setup
    var file = await picker.PickSaveFileAsync();
    // File validation
    using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
    var encoder = await
    BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);
    encoder.SetPixelData(BitmapPixelFormat.Rgba8, 100, 0, 96, 96,
    await renderTargetBitmap.GetPixelsAsync());
    await encoder.FlushAsync();
    I have already used the code snippet. Could you please tell me how to save UIElement tree by having the stream and bitmap encoder id as input?
    Thanks
    Satheesh

    Here you go. Set up the file picker and call our CaptureElementToFile function. In this case it's passing the page to capture the whole screen:
    FileSavePicker picker = new FileSavePicker();
    picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
    picker.SuggestedFileName = "capture.bmp";
    picker.FileTypeChoices.Add("Bitmap File",new List<string>() { ".bmp" });
    StorageFile file = await picker.PickSaveFileAsync();
    CaptureElementToFile(this, file);
    And here's CaptureElementToFile. The BitmapEncoder needs to know information about the size and shape of the pixel buffer and it needs to have the pixels as an Array. If you want to encode to a different size you can include a BitmapTransform.
    async void CaptureElementToFile(UIElement element, StorageFile file)
    RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
    await renderTargetBitmap.RenderAsync(element);
    IBuffer pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
    DisplayInformation dispInfo = DisplayInformation.GetForCurrentView();
    using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);
    encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight,
    (uint)renderTargetBitmap.PixelWidth,
    (uint)renderTargetBitmap.PixelHeight,
    dispInfo.LogicalDpi,dispInfo.LogicalDpi,
    pixelBuffer.ToArray());
    await encoder.FlushAsync();
    --Rob

  • When using Firefox certain videos play but the image is green and distorted.. help?

    Firefox 3.6.8 and 3.5 (I downgraded to see if that would solve the issue)
    Windows 7
    Intel Core i5
    Flash Player: WIN 10,1,53,64
    When using Firefox certain videos play but the image is green and distorted. The image turns into lines and sometimes it half of the screen of the video. Examples are streaming MLB.tv video and some vimeo videos. The odd thing is that it isn’t all Vimeo videos. Is this a flash issue?
    The issue does not happen with Internet Explorer which leads me to believe this is an issue with Firefox. I downgraded to 3.5 and the issue still persists.
    Screen Caps: http://yfrog.com/1x46496103j and http://yfrog.com/n112309689j
    Any help?
    == URL of affected sites ==
    http://

    Try disabling hardware acceleration in your [http://www.macromedia.com/support/documentation/en/flashplayer/help/help01.html Flash settings] (using Firefox, right-click on any Flash object on a webpage, select Settings, uncheck "Enable hardware acceleration on the Display tab).
    Ref:
    http://kb.mozillazine.org/Flash#Performance_or_display_issues_with_certain_Flash_videos

  • My husband saved a load of photos and video clips to icloud, please help.

    my husband saved a load of photos and video clips to icloud, my phone has been taken so i no longer have it but didnt know how i can get up my photos without my phone please help.

    Hi shaza31,
    If your iPhone was set to save photos to Photo Stream, you may be able to access them by turning on Photo Stream on your other devices. The following article may be helpful:
    iCloud: Photo Stream FAQ
    http://support.apple.com/kb/ht4486
    Regards,
    - Brenden

  • I am using adobe photoshop cs6. I am facing a problem. When i save any image as "save for web". After saving image it show cropped. An image show many parts of the image after saving the image. Please help me. Thanks in advance.

    I am using adobe photoshop cs6. I am facing a problem. When i save any image as "save for web". After saving image it show cropped. An image show many parts of the image after saving the image. Please help me. Thanks in advance.

    Just go back in photoshop and use the Slice Select tool, then just click and select the slice and hit delete - if you're not sure which one is the active slice just right click and find the one that has the Delete Slice option.
    It's possible you either added the slices by accident or if you received it from someone they just had the slices hidden. For the future, you can go to View > Show > Slices to display (or hide) slices.

  • When I have resized and saved an image in Photoshop (CS, version 8.0 for Mac) using image size, why is it so large when I open it in preview or another image viewer? Has it actually saved according to the size I specified?

    When I have resized and saved an image in Photoshop (CS, version 8.0 for Mac) using image size, why is it so large when I open it in preview or another image viewer? Has it actually saved according to the size I specified?

    You want to view the image at the Print Size, which represents the size that shows in the Image>Resize Dialog.
    View>Print Size
    Since screen resolution is almost always lower that the print resolution (somewhere between 72 and 96 usually), images will always look bigger on the screen, unless you view them at print size.
    (apple Retina displays have a much higher resolution than normal screens, closer to the average print size resolution)
    more info:
    Photoshop Help | Image size and resolution

  • So I've downloaded a tv series from iTunes onto my macbook pro, for some reason the episodes on my iTunes won't play at all. no sound and no images. any suggestions and help?

    so I've downloaded a tv series from iTunes onto my macbook pro, for some reason the episodes on my iTunes won't play at all. no sound and no images. any suggestions and help?

    Hi,
    As you have match, I suggest that you create a new library by holding ctrl whist launching iTunes. Select create new library. Sign into iTunes Store and activate match. You will now have access to your music and will be able to stream your music.
    Options : get a new external drive formatted for mac and either download music from match or copy music from old drive to new one. Alternatively you could reformat old drive and download music from match - I would not be comfortable using this option as it means erasing drive before being able to use with mac.
    Jim

  • All of my photos are displayed as BW because somehow I've saved a quick develop preset and it saves as BW.  This is for all of my photos.  I can individually undo them but need help in how to get rid of the preset so it goes to Default. thanks

    All of my photos are displayed as BW because somehow I've saved a quick develop preset and it saves as BW.  This is for all of my photos.  I can individually undo them but need help in how to get rid of the preset so all photos goes to Default or as shot. thanks

    Go to the develop module and highlight all of the images in the filmstrip at the bottom of the screen. Then activate Auto-sync and click on the Reset button. That should reset all of the images to your camera default settings.

  • Hyper link of public image(hyperlink or image) can not be saved on windows server 2012 and sharepoint 2010 problem

    hyper link of public image(hyperlink or image) can not be saved on windows server 2012 and sharepoint 2010 problem, is this a bug?
    thanks for any reply.
    Rosone

    It is not a bug, you might be using IE in Windows server 2012 and and browser might be restricting your site actions to respond properly.
    Check this in a different browser or access site in a differ OS.
    Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer.

  • I have two versions of Pr, one is the latest 2014 and when trying to open a Pr2014 session, I get an error message saying the project was saved in a newer version and cannot be opened. Help

    I have two versions of Pr, one is the latest 2014 and when trying to open a Pr2014 session, I get an error message saying the project was saved in a newer version and cannot be opened. Could there be an issue with an older Pr application on the computer? Please help!

    You need to be very careful which project you open in which version.
    For 2014 make sure its on 2014.1 build 81.

Maybe you are looking for

  • Can I get a refund for non-compatible product?

    Have purchased FIFA 12 for my Ipod touch only to find that it is not compatible with the version I have. How do I return and get a refund?

  • Dekstop pictures keep resetting on login???

    I recently added a second monitor to my '06 white 24" iMac running OSX 10.6.4 and ever since installing the second monitor my Desktop Picture settings are being completely ignored? In other words, every time I log in my desktop picture reverts to the

  • Web forms w/ patch 1 tree & call_form crash

    Hi there: I've done my homework and haven't come across anyone else w/ the same problem, so let me see if I can start a grass roots movement here. I've got a tree item in a 6i patch 1 web form that acts as a forms launcher. If you double-click a part

  • Adobe Java API

    Hello and thank you for your valuable time.  I'll get right to it - I have PDFs and I need to extract certain text elements from it.  Not all elements, just certain ones.  I do know the x/y/width/height of the elements I need.  I want to be able to m

  • Lumia 1020 - No Speed Dial

    Having just moved from Android SGS4 I am shocked to find that the Lumia 1020 (possibly the most expensive mobile phone on the market) does not have speed dial under the phone pad keys. Forget about the inconvenient pinning of a contact to the home wi