How do I overlay an PNG on a JPG?

I continued the development of some JAI code a old collegue of mine started on. I've searched on the net, and tried different solutions, but every time I try to save my output file, I get a java.lang.ArrayIndexOutOfBoundsException: 4802
The problem occurs when I try to save the resulting PlanarImage or if I try to do a .getAsBufferedImage() on the result.
The overlay is loaded in another method in the same class, and the overlay image is allways a PNG. The image sent as a parameter to the method below is allways a JPEG.
Can anyone help me out here, what did I get wrong?
This is my code:
public PlanarImage overlayImage(PlanarImage img, String overlayPath, int position, int margin) {
          try{
               float x = 0;
               float y = 0;          
               // Background image. Create a renderable version.
               ParameterBlockJAI pb = new ParameterBlockJAI("renderable");
               pb.addSource(img);
               pb.setParameter("height", (float) img.getHeight());
               RenderableOp src2 = JAI.createRenderable("renderable", pb);          
               // Create a renderable version of the overlay image.
               pb = new ParameterBlockJAI("renderable");
               pb.addSource(getOverlay(overlayPath));
               pb.setParameter("height", (float) getOverlay(overlayPath).getHeight());
               RenderableOp rendOver = JAI.createRenderable("renderable", pb);               
              // Get position
              if (position == TOP_LEFT) {
                   x = margin;
                   y = margin;
              else if (position == TOP_RIGHT) {
                   x = (src2.getWidth() - rendOver.getWidth()) - margin;
                   y = margin;
              else if (position == BOTTOM_LEFT) {
                   x = margin;
                   y = (src2.getHeight() - rendOver.getHeight()) - margin;
              else if (position == BOTTOM_RIGHT) {
                   x = (src2.getWidth() - rendOver.getWidth()) - margin;
                   y = (src2.getHeight() - rendOver.getHeight()) - margin;
              // Move overlay to target position
              ParameterBlock pbx = new ParameterBlock();
              pbx.addSource(rendOver);
              pbx.add(x).add(y);
              rendOver = JAI.createRenderable("translate", pbx, null);          
              // Get the RGB bands.
             pb = new ParameterBlockJAI("bandSelect", "renderable");
             pb.addSource(rendOver);
             pb.setParameter("bandIndices", new int[] {0, 1, 2});
             RenderableOp src1 = JAI.createRenderable("bandSelect", pb);
               // Get the alpha band.
               pb = new ParameterBlockJAI("bandSelect", "renderable");
               pb.addSource(rendOver);
               pb.setParameter("bandIndices", new int[] {3});
               RenderableOp alpha1 = JAI.createRenderable("bandSelect", pb);
               // Setup and create the composite operation.
               pb = new ParameterBlockJAI("composite");
               pb.addSource(src1.createScaledRendering(currentOverlayImg.getWidth(), currentOverlayImg.getHeight(), null));
               pb.addSource(src2.createScaledRendering(img.getWidth(), img.getHeight(), null));          
               pb.setParameter("source1Alpha", alpha1.createScaledRendering(currentOverlayImg.getWidth(), currentOverlayImg.getHeight(), null));
               pb.setParameter("source2Alpha", null);
               pb.setParameter("alphaPremultiplied", false);
               pb.setParameter("destAlpha", CompositeDescriptor.NO_DESTINATION_ALPHA);
               RenderedOp composited =  JAI.create("composite", pb);
               // Overlay the composed image onto the original image.
               pb = new ParameterBlockJAI("overlay", "rendered");          
               pb.setSource("source0", src2.createScaledRendering(img.getWidth(), img.getHeight(), null));
               pb.setSource("source1", composited);          
               returnJAI.create("overlay", pb, null);
          }catch(Exception e){
               System.out.println("Error while overlaying image :: " + e.toString());
          return null;
     }

Use the uninstaller that came with the application.
If no unistaller then drag it to the Trash and empty theTrash.
Allan

Similar Messages

  • How do you switch between web server snapshot jpg and png modes?

    I read in another forum a posting by "NathanK" stating:
    "The snapshot feature of the web server can
    generate images either as png or jpg. In LabVIEW 8.6 and later, the
    default which is generated by the web publishing tool is the png
    format. In this mode everything happens in memory so there is no
    snapshot image file generated.
    In the jpg mode there is a
    temporary file, however it is not always the same file and the file is
    deleted after it is uploaded to the client. I would not recommend
    trying to use this programmatically.
    If you need more
    control over a snapshot of a front panel (and you are using 8.6), I
    would recommend making a custom web service that takes a picture of a
    VI's front panel and returns it to the client. Then you would have
    control over the image."
    I am currently using the web publishing tool snapshot feature with an EXE program written in LV8.6.  However, each time a browser accesses the html file, the EXE file's memory grows by 72KB (this happens with my custom EXE program and with LabVIEW.exe when running the VI in development mode).  I'm assuming this is the png that is generated each time a snapshot is taken, but the program never de-allocated the memory and the program eventually crashes.  I'm aslo assuming that if I switch to "JPG mode", the web server will generate a temporary file and eventually delete it, elminating the memory leak.  The problem is, I don't know how to change the modes from png (default) to jpg.

    I am and have been using the .snap function on many applications since LabVIEW 6.1.  It's very simple, easy to use, does exactly what I want it to do, and is still in the documentation of LabVIEW 8.6, 2009 and 2009 SP1 as being supported. 
    If I am not mistaken, don't you need to have the LabVIEW runtime engine on the target system to use embedded mode?  I don't want to have to try and keep everybody who wants to see a screenshot of my program to have to have a run-time engine installed.  For one reason, I don't know everybody who wants to monitor our system and they literally can be anywhere in the world if the VPN to our network.  Second, those who I do know would would have me install it for them.  Third, why go "backwards" in capability...everybody would ask me "Why do we have to do this now?..we never had to do it before", and I don't want to use my time/energy at work to explain why NI cannot fix a memory leak that has been identified in at least the last 3 versions of LabVIEW and is still not fixed. 
    I had been using either LV 6.1 or 7.1 for a good part of 10 years and had very few problems with them (BTW, DAQmx is the greatest thing every put on a computer EVER).  I finally make the transitioin and start using LV 8.6 on a major test platform last year, got to the very end of it and find this out.  <sigh!>
    It is funny (maybe not), but my work around feels like I just changed the floormats in my Toyota car to keep it from "crashing".
    However, if I am mistaken and you do NOT need to use LV runtime engine for embedded mode, ignore everything I wrote above and please let me know that this is the case and I will look into it.

  • Cloud storage - how can I use my .png file shared in "public mode" like a hosted file ?

    Hi every body,
    I am french and new on the forum so please be indulgent ! (for my english and my questions).
    I am working on HTML signature for my company and I have a little problem.
    to be viewed, my .png files needs to be on a server. So I remember that adobe gave me a 100giga storage for me to use.
    Cool !
    But the problem is that the link only send me to a special view of my file... a jpeg one. So when I try to copy the url I can only use the .jpg
    I want my file !
    So my question is : is it possible that the cloud storage isn't supposed to share any thing else than a miniature of my file and a download button ?
    How can I use it for my signature if I can't acess it but only download it?
    Thank you very much for your time
    Morgan

    Hi Morgan,
    You are correct.  Public link sharing works as follows:
    -  you can share a public URL to your PNG file on Creative Cloud.  The recipient of the URL can view a preview of the file and download the file in the original PNG format or JPG format.
    -  it is not possible to give other users direct access to the original file in Creative Cloud.
    For more info on sharing and collaboration options:
    https://helpx.adobe.com/creative-cloud/help/collaboration.html
    https://helpx.adobe.com/creative-cloud/help/share.html
    Thanks,
    Elba

  • How do I import a .png file to iPhoto?

    How do I import a .png file to iphoto?

    The Save to iPhoto was fixed in yesterday's iPhoto update: iPhoto 9.4.3
    OT

  • How to show 10-bit PNG(TIFF) file in Labview?

    I used NI-IMQA 1409 to grab a 10-bit picture. It only can be save as PNG file in MAX. but I found I could n't display that image file any more? Could any one tell me how I can display that PNG file. Thanks

    First, when you Grab or Snap an image in LabVIEW with the Vision utilities, you will have to use 16bit format. This is a big pain, and a serious waste of memory, but necessary. I strongly recommend that if you are doing any kind of image manipulation or processing, that you keep it 10bit.
    Okay, with that said. To display the image, you need to go to the Picture Tools palette, NOT the IMAQ palette. There you will find the tools to open and display the PNG image. However; you should be able to read the image with the "Read Image File" VI, though as I have never done it, I cannot be certain. Either way, the Picture tools will get you where you need to be.

  • How do I overlay a photo

    I see instructions for overlaying video on iMovie using iOS, but on my iPad how do I overlay a photo to replace the portion of the video while using the soundtrack?

    That is not a feature of iPhoto - suggest to Apple - iPhoto Menu ==> provide iPhoto feedback.
    Use a third party program like Preview or <a href="http://web.me.com/larryhn/iPhoto_08_(version_7.x.x)_FAQ/Graphic_programs.html"> click here for links to some to consider.</a>
    LN

  • How do i save a .png with transparent background?  cannot find in help

    how do i save a .png with transparent background?  cannot find in help

    rickseng
    With what program are you working and with what version of the program and on what computer operating system?
    I suspect that you are working with some version of Photoshop Elements. If that is correct, then be advised that some how
    your thread got posted in the Adobe Premiere Elements Forum (video editing) instead of the Adobe Photoshop Elements Forum (photo editing).
    If Photoshop Elements question, then please re-post your thread in the Adobe Photoshop Elements Forum or wait for a moderator
    here to see your thread here and move it from here to there.
    Photoshop Elements
    Thought....if are creating an image on a transparent background in Photoshop Elements Windows for a Premiere Elements Windows project, then you Save As png or psd.
    Please clarify if I have misinterpreted your question.
    Thank you.
    ATR

  • How do I compress a PNG file in Illustrator?

    How do I compress a PNG file in Illustrator?

    Don’t use .png format for print. It’s not meant for that and can’t have an embedded profile for colour conversion.
    So conversion from RGB to CMYK will be pretty random and probably not match your expectations.
    You should either convert the file to CMYK yourself (using a suitable colour management setup for the printing process in question) or else supply an RGB format that supports colour profiles. .Jpg, .psd, .tif, .pdf, .eps are o.k. but not .png.

  • Forms Central: How can I overlay a textfield over an imported picture?

    How can I overlay a textfield over an imported picture?

    Apologies, been trying all afternoon and then a couple of minutes after posting, I figured it out. Using a property node for the Scenemesh reference, I set the property TextureGenMode to Spherical and it appears to now display the texture on the mesh.

  • How do you convert a PNG File to PDF?

    How do you convert a PNG File to PDF?

    There are several ways, including  ... Right click the .png file in Windows explorer and select Convert to Adobe PDF. Or, click Create PDF on the Acrobat welcome screen. Or, in Acrobat, File > Create > PDF from file

  • How do you overlay the audio from a clip over a iphoto slideshow clip ?

    How do you overlay the audio from a clip over a iphoto slideshow clip ?
    I want the audio from a video clip to be playing over the jpg/slideshow iphoto images ...so you see the slideshow elements but do not see the clip but do here the audio !
    thanks ! HELP!

    How do you overlay the audio from a clip over a iphoto slideshow clip ?
    "Command-Shift-Drag" the Event clip containing the audio you wish to extract and "pin" it to the slideshow already in the Project window.

  • How do you import a .png file into the Final Cut Pro X and at the same time keep the file's original transparency settings?

    How do you import a .png file into the Final Cut Pro X and at the same time keep the file's original transparency settings?

    Go to the Info inspector for the still image and in settings select the alpha type.

  • How to convert a Graphics object into a JPG image?

    I have this simple question about how to make a Graphics object into a JPG file...
    I just need the names of the classes or the packages ... I'll figure out the rest of the details...
    Thanks...

    Anyway this might come in handy
    JPEGUtils.java
    ============
    * Created on Jun 22, 2005 by @author Tom Jacobs
    package tjacobs.jpeg;
    import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.awt.image.RenderedImage;
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import javax.imageio.ImageIO;
    import com.sun.image.codec.jpeg.JPEGCodec;
    import com.sun.image.codec.jpeg.JPEGEncodeParam;
    import com.sun.image.codec.jpeg.JPEGImageDecoder;
    import com.sun.image.codec.jpeg.JPEGImageEncoder;
    * Utilities for saving JPEGs and GIFs
    public class JPEGUtils {
         private JPEGUtils() {
              super();
         public static void saveJPEG(BufferedImage thumbImage, File file, double compression) throws IOException {
              BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
              saveJPEG(thumbImage, out, compression);
              out.flush();
              out.close();
         public static void saveJPEG(BufferedImage thumbImage, OutputStream out, double compression) throws IOException {
              JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
              JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
              compression = Math.max(0, Math.min(compression, 100));
              param.setQuality((float)compression / 100.0f, false);
              encoder.setJPEGEncodeParam(param);
              encoder.encode(thumbImage);
         public static BufferedImage getJPEG(InputStream in) throws IOException {
              try {
                   JPEGImageDecoder decode = JPEGCodec.createJPEGDecoder(in);
                   BufferedImage im = decode.decodeAsBufferedImage();
                   return im;
              } finally {
                   in.close();
         public static BufferedImage getJPEG(File f) throws IOException {
              InputStream in = new BufferedInputStream(new FileInputStream(f));
              return getJPEG(in);
         public static void saveGif(RenderedImage image, File f) throws IOException {
              saveGif(image, new FileOutputStream(f));
         public static void saveGif(RenderedImage image, OutputStream out) throws IOException {
    //          Last time I checked, the J2SE 1.4.2 shipped with readers for gif, jpeg and png, but writers only for jpeg and png. If you haven't downloaded the whole JAI, and you want a writer for gif (as well as readers and writers for several other formats) download:
    //          http://java.sun.com/products/java-media/jai/downloads/download-iio.html
              ImageIO.write(image, "gif", out);
         public static void main(String[] args) {
              // TODO Auto-generated method stub
    }

  • I just set up a new computer running Windows 8.1. When I go to my icloud photostream, the pictures are in PNG format NOT JPG. When I open and upload photos from the photostream, the resolution is so low that the image quality is terrible. Help?!?

    I just set up a new computer running Windows 8.1. When I go to my icloud photostream, the pictures are in PNG format NOT JPG. When I open and upload photos from the photostream, the resolution is so low that the image quality is terrible. Help?!?

    Hey Sierra, You can do just what you have stated. My question, what is your "other"? If it is over 1.5 GB you most likely have corrupt files. Doing a Restore to New, Factory restore should correct it. Just make sure you make a full backup of all information on your iPod to your computer before you restore, so you don't lose your stuff, contacts, videos, pictures, non-iTunes music, etc, use the cable and connect with your computer. Then, via cable, connect to your computer, run the Restore to new, don't use your backup. Treat this iPod as if it was your first one ever. When restore is done, set up and add what info you wish to install on this iPod. The music apps etc you purchased should be on your computer, if not you should be able to retrieve purchased apps and music from iTunes. Any music, videos, apps not purchased from iTunes will be lost to you if you do not save them to your computer or the cloud first. When your done, make a current Backup and you should good to go. Hope this helps. Good luck. Cheers.

  • Hi. I'm using illustrator cs6 on pc. I've made a scientific figure for a paper and now I'm trying to export as a png or save for microsoft office. Despite my figure being in the middle of my artboard, it always comes out bottom left in the png file or jpg

    Hi. I'm using illustrator cs6 on pc. I've made a scientific figure for a paper and now I'm trying to export as a png or save for microsoft office. Despite my figure being in the middle of my artboard, it always comes out bottom left in the png file or jpg. Must be making a school boy error! Please help!

    In similar cases, my solution is to "select all" then "deselect" only the artwork I want to keep and "delete". If I'm curious I may "cut" then "paste" to see what shows up in the center of the screen. it is usually some stray point. or other element out direct sight.

Maybe you are looking for

  • ITunes 7.1.1 won't recognize iPod and gets stuck.  Help needed!

    Since I updated to version 7.1.1, iTunes does not recognize my iPod (a 15GB Model M9460LL). I can work with iTunes before I connect the iPod, but when I do connect it, iTunes freezes up: the beach ball spins endlessly, and the iPod screen stays on "d

  • Few answers i am looking for ...

    Hello all, Happy New Year to All I recently got interview and not able to find answers for few questions ... as : Can we Track the Promoted property in Biztalk administrator console ( message-body) ? Two part of Property promotion ? not like...two wa

  • "open file in Photoshop" doesn't work any more.

    When I right clicked a picture in Lr (most recent version) and selected "open file in Ps (CC 2014)" Photoshop launched, but the image didn't show up. I tried several times, with Ps closed or open, but to no avail. Opening the file as a "smart object

  • Sudden Strange Decrease in Sync Speed

    On the afternoon of Thursday 4/3/2010 I had a strange change in my sync speed. For about the past year I have enjoyed a solid 3.1 meg sync and same IP Profile. Sometimes its goes up to 3.5, but never below 3 meg. I know my neighbours get around 2 meg

  • Best approach for combinng cubes of different data

    Hi Guys, I have two different cubes with much different data in them and only a couple of shared characteristics. Im looking to merge most of the data of cube 2 with the data of cube number 1. Multiprovider wont work( not many shared characteristics)