ByteBuffer to BufferedImage over WritableRaster: Image is upside down

Hey all!
I have a native Buffer containing RGB-Values (3 bytes per Pixel). I found a Code-Sample in this Forum which works fine for me:
[http://forums.sun.com/thread.jspa?messageID=10784665#10784665]
The thing is, the BufferedImage is "Upside down". Is there a simple way to tell the Raster (or whatever) in which direction the buffer should be read?
I don't wan't to use image transformation because of the time needed by CPU for the transformation.
Best regards,
Billie

The BufferedImage is stored in a File (JPEG).
The callback-Function is called from JNI and the ByteBuffer contains the RGB value's. This code creates my BufferedImage:
    private ByteBuffer buffer = null;
    private int[] bOffs = { 0, 1, 2 };
    private ColorModel colorModel =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
            new int[] { 8, 8, 8 },
            false,
            false,
            Transparency.TRANSLUCENT,
            DataBuffer.TYPE_BYTE);
     * Called within JNI
     * @param byteBuffer the native memory buffer
     * @param width the image with in pixels
     * @param height the image height in pixels
     * @param bitCount the number of bits per pixel
    protected synchronized void callback(ByteBuffer byteBuffer, int width, int height, int bitCount) {
        String method = "callback(ByteBuffer, int, int, int)";
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(method, "byteBuffer="
                + byteBuffer
                + ",width="
                + width
                + ",height="
                + height
                + ",bitCount="
                + bitCount);
        try {
            if (buffer == null) {
                buffer = ByteBuffer.allocate(byteBuffer.capacity());
            buffer.position(0);
            buffer.put(byteBuffer);
            WritableRaster raster =
                Raster.createInterleavedRaster(new DataBufferByte(buffer.array(), buffer.capacity()),
                    width,
                    height,
                    width * 3,
                    3,
                    bOffs,
                    null);
            bfImage = new BufferedImage(colorModel, raster, false, null);
        } catch (Exception e) {
            LOGGER.error(method, "Error createing BufferedImage", e);
        notify();
    }And this code stores the image on disk:
        ImageWriterSpi imageWriterSpi = (ImageWriterSpi) IIORegistry
            .getDefaultInstance()
            .getServiceProviderByClass(Class.forName(properties.getProperty(KEY_IMAGE_SPI))); // com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi
        imageWriter = imageWriterSpi.createWriterInstance();
                    imageWriter.reset();
                    imageWriter.setOutput(ImageIO.createImageOutputStream(new FileOutputStream(new File(
                        directory,
                        fileName + ".jpg"))));
                    imageWriter.write(null, new IIOImage(bufferedImage, null, null), imageWriteParam);The BufferedImage isn't touched between this two parts.

Similar Messages

  • In transferring a video file from iPhone 4s to a flash drive then to a Axer FHD-45 pocket projector the image turns upside down. It is right side up in the computor and the flash drive. Any help?

    In transferring a video from iPhone 4s to a flash drive then to a Axer FHD-45 pocket projector the image is upside down. It is right side up in the computor and the flash drive. Any help?

    Have you tried transferringing the videos via usb (sinc you're having trouble transferring them with PhotoSync) as described here: http://support.apple.com/kb/HT4083 and just transferring the photos with PhotoSync?

  • When I send emails with photos from iPhoto recipients often tell me images are upside down.  What would cause that?

    When I send emails with photos from iPhoto recipients often tell me images are upside down.  What would cause that?

    Found this :
    https://discussions.apple.com/thread/3431867?start=0&tstart=0
    by doing this :
    http://www.google.com/search?q=images+are+upside+down+ios

  • After PDF to jpg image conversion, image generated upside down

    Hi,
    Now i have replaced the latest .jar file for Jpedal, jai_codec, jai_core and have made modifications in the code to fit the latest version of the .jar files.
    But the image is getting generated Exact Upside Down. How can i resolve this issue?
    Regards
    Ravishankar V K

    perhaps there's an orientation parameter in the new API or they changed the defaults? I'm not sure, you could always rotate it 180 degrees manually.

  • My tecra images, are upside down!!!! I don't know what I did!!!

    Guys, may be this is easy, but I never passed for this before. My Tecra A8-SP 4012; JUST SHOW THE DESKTOP, AND EVERY IMAGE ARE UP SIDE DOWN!!!!
    WHAT I MUST DO TO GET THE RIGHT UPSIDE AGAIN!!????
    THANKS!
    [email protected]
    ALEX POTRO CAMARENA

    You don't say what Operating System you are using.  Assuming Windows 7 (and probably for earlier OS's also but I don't know), go to Start/Control Panel/Display/Adjust Resolution/In the "Video Orientation" box, click on the drop down arrow and choose "Landscape".  It is probably now showing "Landscape Flipped".
    You may also get there by simply right clicking on the desktop and choosing Screen Resolution and then do the above.
    C.B.
    Toshiba Sat. C75D-B7260 Win 8.1 64 Bit--Toshiba Sat. L775D-S7132 Win 7 HP SP1 64 Bit and Win 10 PRO Technical Preview--Toshiba Sat. L305-S5921 Win Vista SP2 32 Bit

  • Vision Builder for Automated Inspection: Image randomly appears upside down

    Hi everyone,
    I seem to be having a rather unusual problem here. I'm using an IDS UI-6280 camera to simply take a picture and log it to a file every minute. However, about 50% of the times when I start VBAI, the image appears upside down. The only solution I have found so far is to close VBAI and start it again. It usually takes a couple of tries before the image turn back up again, and then it's okay for the next couple of times I open VBAI. I have found no clues at all as to what could be causing this. Has anyone experienced something like this before?
    Clarification:
    - Once VBAI is running, the image does not flip randomly. If the first image is upside down, so are all the subsequent images. If the first image is upright, so are all the subsequent images. The flipping only seems to happen when I open VBAI. 
    - The flipping only seems to happen when I use VBAI. Using the IDS software always gives an upright image.
    - There is about a 50-50 distribution between upside down and upright images. However, there seems to be some pattern in when the flipping occurs. I just opened and closed VBAI 10 times, the upside down and upright state occured in an order like this (x=upside down, 0=upright): x0xxx00000
    Any help or insights would be greatly appreciated!

    1. Does the camera have an attribute for flipping it? If it does, the camera may not handle this attribute well when VBAI sets this attribute in conjunction with the other attributes as fast as VBAI can when it is initializing the camera. Most cameras respond when they are done and ready for the next attribute to be set, but some cameras respond before the attribute is done being set and can get in a messed up state if another attribute is set too quickly. You could try using the Read/Write Attribute Step in VBAI to manually set the flip attribute off before you acquire (make sure to set the flag to always set this attribute even if the current value is the same as what it will set to).
    2. If you acquire an image in MAX, is it upside down? Try Clicking on the camera in MAX, acquire, click to another camera or to another device (this will release the resources for the camera), click back on camera again in MAX and acquire again. Repeat this several times and see if you have the same flipping behavior as in VBAI.
    3. If you create a new inspection with just an acquisition step, does it still happen? Make sure not to change any of the default attributes for this test case. This will ensure the VBAI step uses the same settings you would see in MAX.
    4. What if you try using Snap Shot mode in the acquisition step instead of Immediate mode.
    Hope this helps,
    Brad

  • Image upside down in magic bullet looks viewer?

    using fcp x 10.0.4 with magic bullet looks for weeks. Now when I apply looks and the looks viewer opens the image is upside down. Have deleted the looks preferences and then uninstalled and reinstalled but image remains inverted. How can I get image upright? 

    At first glance I thought it was a stunt pilot until I noticed the bit of ground at the top!  
    Seriously, I had the same problem after I updated FCP X to version 10.0.4.
    Anyone else with this problem can cure it by updating Magic Bullet Looks to version 2.0.7
    This is Red Giant's description of the problem and solution:-
    http://www.redgiantsoftware.com/blog/tag/final-cut-pro-x/

  • Screen image display is upside down

    I have a user with a Portege S100 who says that the image appears upside down - is this a facility or a problem? If a facility how does she return it to normal?
    Thanks

    As in the previous posting suggested the graphic card supports a NV rotate option.
    I assume the user has changed the screen to inverted landscape (180 degree rotation)
    As far as I know there is a key combination to change this option:
    Ctrl + Shift + R

  • IMac iSight Camera Upside-Down?

    I just got a new iMac C2D 2.4GHz 24" and when I got to the screen where it asks to take a Snapshot to use as my Account Photo the image appeared upside down. I then figured it might work correctly in Photo Booth but it appears that it does not. When I open Photo Booth it shows my picture upside down.
    I downloaded iGlasses to see if rotating it would fix the problem and it does, but I'd rather not have to set that up and pay 10$ to correct something that shouldn't even be happening.
    Is there anything that I can do? Is there a setting I could change?

    Hi SkawtS
    Sound like the iSight may have been installed upside down at the factory???
    I would take it or send it back for a replacement right away... here's the link to [Contact Apple Support|http://www.apple.com/support/contact>
    Dennis

  • Clips imported from my itouch are upside down in editor

    I am a newbie, but have edited 10 or more videos and never have had this problem. I imported a video clip taken from my itouch. In the bin it is right side up, but when I pull it to the editor, the video image is upside down. How do I correct that.
    (PS. The video is right side up when I watch it in quicktime player before I import it)

    I must not be selecting the clip properly because nothing is changing. I have gone to the motion tab and ran the clock to turn the image 180 but it is not changing on the editor or the canvas screen.

  • How to add an Image layered over another Image?

    In our application, we display a big image file in the main application window.
    Now, we want to display customer's image(like their logo etc.,) just layered over main image on the top-left corner, restricted in size.
    Tried to visualize it !
    |------| |
    | |
    | |
    Is it possible to show a JLabel over another JLabel?

    Solution 1:
    JLabel is a container, So you can add any component on top of JLabel but normally it will not display but if you set any layout then you can see the added component.
        public static void solution1() {
         JFrame frame = new JFrame();
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         JLabel bigImg = new JLabel(new ImageIcon("F:\\tmp\\bigImg.jpg"));
         JLabel logo = new JLabel(new ImageIcon("F:\\tmp\\logo.gif"));
         frame.getContentPane().add(bigImg, BorderLayout.CENTER);
         bigImg.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
         bigImg.add(logo);
         frame.pack();
         frame.setVisible(true);
        }Disadvantage : if the label size was changed depends on the layout the position of the logo goes outside of the big image(in the above example maximize the window to see that issue).
    Solution 2:
    draw the logo image on top of the big image.
        public static void solution2() {
         JFrame frame = new JFrame();
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         ImageIcon bigImg = new ImageIcon("F:\\tmp\\bigImg.jpg");
         ImageIcon logo = new ImageIcon("F:\\tmp\\logo.gif");
         int w = bigImg.getIconWidth();
         int h = bigImg.getIconHeight();
         BufferedImage bf = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
         Graphics2D g2d = bf.createGraphics();
         g2d.drawImage(bigImg.getImage(), 0, 0, frame);
         g2d.drawImage(logo.getImage(), 0, 0, frame);
         JLabel label = new JLabel(new ImageIcon(bf));
         frame.getContentPane().add(label, BorderLayout.CENTER);
         frame.pack();
         frame.setVisible(true);
        }Advantage : whenever the label component size changed the logo must be on the big image of the same position because the logo was painted on top of the big image.

  • Send BufferedImage over the network

    I have already successfully setup a client/server connection. The issue, is when I send the BufferedImage over the network, it says:
    "Caused by: java.io.NotSerializableException: java.awt.image.BufferedImage"
    Can someone please tell me how to fix this?

    Like the exception say, BufferedImage is not serializable. You cannot serialize it. The problem will go away if you don't try to serialize it. Of course, that doesn't answer the question you really meant to ask... which I'll leave for somebody else.

  • Live video image upside down

    I have a Canon 600D, T3i and I am trying to use the Live HD Video with a non-Canon lens and viewing on a 23" hd Monitor. The image is reversed and even when I change the settings on the camera to "flip" the image, it will not do it.  I have a friend who has the same camera and lens he does not have this issue.  Is there something I can do to resolve this?

    Thanks, but we use different monitors.  I have no issues here. 
    If he places an object in the bottom right corner of the FOV, it shows up upside down in the top left corner.  ie, placing a pencil (like an arrow) under the lens on the bottom right side pointing up, it shows up in the top left corner pointing down.  There s no monitor control to flip the image, but there is with the T3i.   It has a built-in 3" screen that can flip over.  This setting keeps the image erect on the view screen and it has a selection to do the same with a monitor as well.  I have this setting turned on, and I'm not having his issue.

  • I am running Photoshop CC 2014 on Windows 8.1 with an AMD quad core processor and AMD E1-2100 APU with AMD Radeon HD 8210 Graphics Card. I have installed the latest driver version 13.152.0.0. When I activate puppet warp, the mesh appears over the image an

    I am running Photoshop CC 2014 on Windows 8.1 with an AMD quad core processor and AMD E1-2100 APU with AMD Radeon HD 8210 Graphics Card. I have installed the latest driver version 13.152.0.0. When I activate puppet warp, the mesh appears over the image and I can place the first pin.  However, when I go to add the second pin, Photoshop crashes. I have tried with on a new, blank file, with just a few lines on it, but, as soon as I place the first pin, the image disappears, and then, as soon as I click anywhere else in the image, Photoshop crashes. I have followed all the online advice about settings under the Preferences/Performance interface, but nothing fixes the problem. Can anyone please help?

    BOILERPLATE TEXT:
    If you give complete and detailed information about your setup and the issue at hand, such as your platform (Mac or Win), exact versions of your OS, of Photoshop and of Bridge, machine specs, such as total installed RAM, scratch file HDs, video card specs, what troubleshooting steps you have taken so far, what error message(s) you receive, if having issues opening raw files also the exact camera make and model that generated them, etc., someone may be able to help you.
    A screen shot could be very helpful too.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • How can I place a custom table over an image?

    I have a graphic embedded in the Master Page at the start of every chapter like this.
    I created a borderless Custom Table without the data that I want to place over the image so it looks like the text is typed on the notebook paper. I apparently can't add this to the Master Page, but I can't seem to figure out how to do this on the Body Page either. The table is the same as in my previous question but included here again for reference. While the borders are evident here, I will turn them off when I get this placed. The merged cells are for graphics that will change every Lesson. Appreciating this forum as always. Someday I hope I have enough knowledge to help other people here...
    Thanks,
    Laurie

    Laurie,
    You need to have a text frame over the area that you want your table to appear. On the Master Page, use the graphics tools to draw the text frame (Body not Background type) where you need it. Then on the Body pages insert the table. You may need to play with the positioning of the graphic on the Master Page and perhaps use the Format > Page Layout > Line Layout > Baseline Synchronization option as well as the Table Row Height properties to get things to properly align.

Maybe you are looking for

  • Acrobat x 10.1.0 and pitstop pro 10 u 2 makes opening pdfs slow

    As we know pistop is a must plugin for those who reorginase pdf files. I was trying this program and found it works very well before ver acrobat 10.1.0. But when I updated to acrobat 10.1.0, Openning pdf file becomes a hard thing,taking 30 seconds or

  • 10.6.7, the 2011 MBP, and the death of easy cloning....

    I'm a photographer and whenever I've hit the road in the past, I'd clone my MacPro boot drive to an external, then boot my MacBookPro from the external, clone the external to the internal on the MBP and I'd be off, with an exact replica of my desktop

  • Table for Planned order

    Hi, Can anyone please tell me the name of Table where I can see those planned orders which have been converted to Process order. AFKO and AFPO does not have the required info. It does have refernce to the planned order but it does not give the other

  • A850+ with chinese characters on phone app despite UK English setting

    Have just received a new 850+ running Android  4.2.2 and firmware A850+_S118_140226 Pretty much all the apps show English except the inbuilt phone app which is mixed English/Chinese.  For example, under an incoming number are Chinese characters.  I'v

  • How to activate ACROBAT X PRO?

    HELP!!!!  I have the teacher/student edition for acrobat X pro.  I originally downloaded to my desktop.  However, I now have a laptop w/o drive.  I downloaded the 30 day trial which has expired.  I have the product/activation code from my orig. softw