Graphics, ImageIO, and 32-bit PNG images with alpha-channels

I have a series of 32-bit PNG images, all with alpha channels. I'm using ImageIO.read(File) : BufferedImage to read the PNG image into memory.
When I call graphics.drawImage( image, 0, 0, null ); I see the image drawn, however all semi-transparent pixels have a black background, only 100% transparent pixels in the source image are transparent in the drawn image.
The Graphics2D instance I'm drawing to is obtained from a BufferStrategy instance (I'm painting onto an AWT Canvas).
Here's my code:
Loading the image:
public static BufferedImage getEntityImage(String nom, String state) {
          if( _entityImages.containsKey(nom) ) return _entityImages.get( nom );
          String path = "Entities\\" + nom + "_" + state + ".png";
          try {
               BufferedImage image = read( path );
               if( image != null ) _entityImages.put( nom, image );
               return image;
          } catch(IOException iex) {
               iex.printStackTrace();
               return null;
     private static BufferedImage read(String fileName) throws IOException {
          fileName = Program.contentPath + fileName;
          File file = new File( fileName );
          if( !file.exists() ) return null;
          return ImageIO.read( new File( fileName ) );
     }Using the image:
Graphics2D g = (Graphics2D)_bs.getDrawGraphics();
g.setRenderingHint( RenderingHints.KEY_ANTIALIASING , RenderingHints.VALUE_ANTIALIAS_ON);
public @Override void render(RenderContext r) {
          Point p = r.v.translateWorldPointToViewportPoint( getLoc() );
          int rad = getRadius();
          int x = (int) p.x - (rad / 2);
          int y = (int) p.y - (rad / 2);
          BufferedImage image = Images.getEntityImage( getCls(), "F" );
          r.g.drawImage( image, x, y, null );
     }

You may want to check on you system and see what ImageReaders are available, it could be ImageIO is just not picking the best one, if not, then you can use getImageReaders to get an iterator of image readers, then choose the more appropriate one.

Similar Messages

  • Export PNG images with alpha channel from flash

    Hi,
    I have this FLA with animation and when played, the animation has alpha channel. I can’t understand why when I look in the library I see the frames without the alpha channel and also when I try to export/extract the image again the image don’t have alpha channel.
    How is it that in flash this image has alpha channel and how to get it out like that into PNG?
    Here is the link to download the FLA:
    http://download759.mediafire.com/nb749r29220g/e0636ab0ru6ouoa/Untitled-1.fla

    "when played, the animation has alpha channel"
    how are you playing the animation? control/enter in Flash, Publishing to a Web page or what?
    How can you tell that the animation has the alpha channel? What exactly are you seeing?
    What is the aniimation? a series of images, one image moving? Are teweens imvolved?
    " when I try to export/extract the image again the image don’t have alpha channel"
    How are you exporting the image? is it a single image? or a series of frames that makes up an animation?
    What was the file format of the original image? you brought that image into Flash and animated it? Now you want to export as a .png with transparency?
    Have you ever tried to export a  simple .png before so that you see and understand the dialog box that pops up during export? are you chosing "24 bit with alpha channel" in the "Colors" choice?
    For those of us who may not want to download your file, please provide a more detailed describtion of everything related to this question.
    Best wishes,
    Adninjastrator

  • Automator or Applescript using png files with alpha channel

    I have hundred of png files with alpha channel.
    I want to suppress alpha channel.
    How can i do it using Automator or Applescript ?
    Thank you very much.

    You can use the free command line image processing tool ImageMagick in your Applescripts or Automator workflows, as well as from a Terminal shell.
    You can download ImageMagick from http://www.imagemagick.org, but Cactuslab has simplified installation by putting together an installer package. It’s available at  http://cactuslab.com/imagemagick/. Download the package and double-click on it. Follow the instructions to install. It will install ImageMagick into /opt/ImageMagick and add it to your $PATH by creating a file in /etc/paths.d/. Restart your computer for the changes to take effect.
    The two ImageMagick commands we’re concerned with are “convert” and “mogrify”. Convert is more efficient for multiple and piped operations on the same image file, and mogrify is more efficient for batch processing. Generally speaking, convert will output a file separate from the input file. Unless a path is specified, mogrify will overwrite the input file with the output file. An important distinction.
    You can perform various operations on the alpha channel using arguments after either the convert or mogrify command. Two of the available arguments are:
    -alpha off - Disables the image's transparency channel. Does not delete or change the existing data, just turns off the use of that data.
    -alpha remove - Composite the image over the background color.
    Also of use are the -flatten and -background options:
    -flatten - overlay all the image layers into a final image and may be used to underlay an opaque color to remove transparency from an image.
    -background - sets the background color.
    Start off using the convert command with a single image to see the effect and adjust to your liking. Once you’ve achieved the desired outcome, then use the mogrify command to batch process the chosen images.
    Before getting into how to use Automator or Applescript in your workflow, use Terminal and the command line to see the effect on a single image. Copy one image to your ~/Desktop. In Terminal change the directory to ~/Desktop by typing the following command and pressing the Enter key:
    cd ~/Desktop
    Then choose the option you are looking for, -alpha remove for instance, type the following command and press the Enter key:
    convert input-photo.png -alpha remove output-photo.png
    You can check the alpha channel (transparency) and background in the Preview app, go View > Show Image Background from the menu bar.
    Once you’re ready to batch proces, place all the photos you want to convert with the same command into one folder. Copy the folder to your ~/Desktop. Let’s assume you’ve labeled the folder “InPhotos”. It’s prudent to manipulate copies in case something goes amiss. In that event you can copy the folder with the originals again and start over. Create a new empty folder on your ~/Desktop and call it “OutPhotos”. Let’s also assume your home directory is called “Me”. The following command will process the photos from the InPhotos folder and put them in the OutPhotos folder:
    mogrify -alpha remove -path /Users/me/Desktop/OutPhotos/ /Users/me/Desktop/InPhotos/*png
    According to Apple Technical Note TN2065:
    "when you use just a command name instead of a complete path, the shell uses a list of directories (known as your PATH) to try and find the complete path to the command. For security and portability reasons, do shell script ignores the configuration files that an interactive shell would read"
    So, you need to use the full path to to ImageMagick commands, unlike in the shell where you can just use the command name.
    To batch process using Automator, use the “Run Shell Script” action (note: retain the single space at the beginning of the last line):
    /opt/ImageMagick/bin/mogrify \
    -alpha remove \
    -path /Users/Me/Desktop/OutPhotos/ \
    /Users/Me/Desktop/InPhotos/*png
    To batch process using Script Editor (Applescript), use the “do shell script” command:
    do shell script "/opt/ImageMagick/bin/mogrify -alpha remove -path /Users/pd/Desktop/OutPhotos/ /Users/pd/Desktop/InPhotos/*png"
    Further info on ImageMagick:
    http://www.imagemagick.org/script/command-line-options.php#alpha
    http://www.imagemagick.org/Usage/masking/#remove
    http://www.imagemagick.org/index.php
    http://www.imagemagick.org/script/command-line-tools.php
    http://www.imagemagick.org/script/command-line-options.php
    Examples:
    The original PNG image:
    -alpha off:
    -alpha remove:
    -background black -flatten:
    -background blue -flatten:
    -channel alpha -evaluate Divide 2:
    -channel alpha -evaluate Divide 2 -background black -flatten:

  • ImageIO PNG Writing Slow With Alpha Channel

    I'm writing a project that generates images with alpha channels, which I want to save in PNG format. Currently I'm using javax.ImageIO to do this, using statements such as:
    ImageIO.write(image, "png", file);
    I'm using JDK 1.5.0_06, on Windows XP.
    The problem is that writing PNG files is very slow. It can take 9 or 10 seconds to write a 640x512 pixel image, ending up at around 300kb! I have read endless documentation and forum threads today, some of which detail similar problems. This would be an example:
    [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6215304|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6215304]
    This surely must be resolvable, but after much searching I've yet to find a solution. If it makes any difference, I ONLY want to write png image, and ONLY with an alpha channel (not ever without), in case there are optimisations that that makes possible.
    If anyone can tell me how to address this problem, I'd be very grateful.
    Many thanks, Robert Redwood.

    This isn't a solution, but rather a refinement of the issue.
    Some of the sources I was reading were implying that the long save time might be due to a CPU heavy conversion process that had to take place before the BufferedImage could be saved. I decided to investigate:
    I loaded back in one of the (slowly) saved PNG images using ImageIO.read(file). Sure enough, the BufferedImage returned differed from the BufferedImage I had created. The biggest difference was the color model, which was DirectColorModel on the image I was generating, and was ComponentColorModel on the image I was loading back in.
    So I decided to manually convert the image to be the same as how it seemed to end up anyway. I wrote the following code:
          * Takes a BufferedImage object, and if the color model is DirectColorModel,
          * converts it to be a ComponentColorModel suitable for fast PNG writing. If
          * the color model is any other color model than DirectColorModel, a
          * reference to the original image is simply returned.
          * @param source The source image.
          * @return The converted image.
         public static BufferedImage convertColorModelPNG(BufferedImage source)
              if (!(source.getColorModel() instanceof DirectColorModel))
                   return source;
              ICC_Profile newProfile = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
              ICC_ColorSpace newSpace = new ICC_ColorSpace(newProfile);
              ComponentColorModel newModel = new ComponentColorModel(newSpace, true, false, ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);
              PixelInterleavedSampleModel newSampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, source.getWidth(), source.getHeight(), 4, source.getWidth() * 4, new int[] { 0, 1, 2, 3 });
              DataBufferByte newDataBuffer = new DataBufferByte(source.getWidth() * source.getHeight() * 4);
              ByteInterleavedRaster newRaster = new ByteInterleavedRaster(newSampleModel, newDataBuffer, new Point(0, 0));
              BufferedImage dest = new BufferedImage(newModel, newRaster, false, new Hashtable());
              int[] srcData = ((DataBufferInt)source.getRaster().getDataBuffer()).getData();
              byte[] destData = newDataBuffer.getData();
              int j = 0;
              byte argb = 0;
              for (int i = 0; i < srcData.length; i++)
                   j = i * 4;
                   argb = (byte)(srcData[i] >> 24);
                   destData[j] = argb;
                   destData[j + 1] = 0;
                   destData[j + 2] = 0;
                   destData[j + 3] = 0;
              //Graphics2D g2 = dest.createGraphics();
              //g2.drawImage(source, 0, 0, null);
              //g2.dispose();
              return dest;
         }My apologies if that doesn't display correctly in the post.
    Basically, I create a BufferedImage the hard way, matching all the parameters of the image I get when I load in a PNG with alpha channel.
    The last bit, (for simplicity), just makes sure I copy over the alpha channel of old image to the new image, and assumes the color was black. This doesn't make any real speed difference.
    Now that runs lightning quick, but interestingly, see the bit I've commented out? The alternative to setting the ARGB values was to just draw the old image onto the new image. For a 640x512 image, this command (drawImage) took a whopping 36 SECONDS to complete! This may hint that the problem is to do with conversion.
    Anyhow, I got rather excited. The conversion went quickly. Here's the rub though, the image took 9 seconds to save using ImageIO.write, just the same as if I had never converted it. :(
    SOOOOOOOOOOOO... Why have I told you all this?
    Well, I guess I think it narrows dow the problem, but eliminates some solutions (to save people suggesting them).
    Bottom line, I still need to know why saving PNGs using ImageIO is so slow. Is there any other way to fix this, short of writing my own PNG writer, and indeed would THAT fix the issue?
    For the record, I have a piece of C code that does this in well under a second, so it can't JUST be a case of 'too much number-crunching'.
    I really would appreciate any help you can give on this. It's very frustrating.
    Thanks again. Robert Redwood.

  • Adding logo with Alpha channel to Quicktime and exporting as .mp4

    I'm adding a PNG file with alpha channel to my existing movie file using "Add to Selection and Scale".
    I then have my movie with the overlayed graphic.
    When I then Export as an mp4, the alpha channel is ignored!
    Any help, anyone?

    Yes it looks perfect in Quicktime.
    But for some reason I can't save it as anything else or even export a still frame without the alpha being ignored and the image going all fuzzy.

  • Moving images with alpha

    In Pages '09, images with alpha channels can be difficult to deal with, especially if the alpha is a bigger part of the object than the non-alpha portion.  The issue is that you cannot move an object by clicking on an area that is transparent.  For most images, this is intuitive and helpful, but for some things it is infuriating.  For example, when pasting in a PDF or image object of a MathType equation, it is quite difficult to reposition the image quickly, because great care must be taken to click on a letter in order to drag the object.  To make matters worse, the edge detection of the non-alpha portions of the object is not extremely precise, so it can appear that you are clicking on a legal part of the image, but you will get no response from pages.
    My question is this: do any of you know if there is a preference somewhere that controls whether alpha is selectable or not?  I would just like to be able to click anywhere in the image box and move the image.  It doesn't matter if it is a support preference or requires fiddling with a plist somewhere.  Anything would be helpful.  Thanks.

    Dream on,
    Well, the World needs more Yoyo Ma types, so I hope you are successful.
    If you Command-Click in the Margin and Drag across the page, you will catch the object in a wide net. Then you can manipulate it with the arrow keys, or Shift-Arrow for larger moves.
    Jerry

  • What codec to convert .MXF and MP4 files into to use with alpha channels in Ae and Pr CS6?

    When I import .mxf File, shot on a Canon C300, into after effects, the alpha channel options are greyed out, when I look in, interpret footage, main. This also is the case importing .MP4 files, shot on a Gopro hero 3. I used to use final cut and using compressor convert the files to pro res 4444 or 422. What's my new workflow for preparing files with alpha channels to use in After Effect and Premiere and do I use Media Encoder to do it?

    When I import .mxf File, shot on a Canon C300, into after effects, the alpha channel options are greyed out, when I look in, interpret footage, main. This also is the case importing .MP4 files, shot on a Gopro hero 3.
    Better question: Where do you expect that Alpha channel to come from and contain any useful info for transparency? You're making a fuss over a non-issue. Unless you apply keying or other methods of creating transparency, even if there were an Alpha channel it would be fully opaque and then what's the point?
    Mylenium

  • Why can't I see the Finder thumbnails for .mov files with alpha channels?

    Ever since I upgraded to Mavericks I haven't been able to see the thumbnail for or preview using spacebar any .MOV clips that contain alpha channels in Finder. PSDs and PNGs with alpha channels are fine, and I can still see their thumbnails and previews, it's just .MOV clips with alpha. Here are a couple screenshots:
    Most of these clips are using a PNG codec, but I converted on to the Animation codec and tested it in After Effects to make sure it kept the alpha channel and it did, but the same thumbnail error persists.
    Any idea why this might be or how to fix it?
    27" iMac late 2012
    1TB Fusion
    NVIDIA GeForce GTX 680MX 2048 MB
    16GB RAM
    OS X Mavericks
    Thanks.

    ok, have copied the photos again from the memory card and hey presto, it all works fine.  So in summary...for RW2 files from GF1 camera, I have no thumbnail images, couldn't view in Preview, and neither Quickview nor Coverview were working.  Ran the bit of code provided at "https://discussions.apple.com/message/18369759#18369759" (thanks to Snoop Dogg) and then recopied the photos onto my Mac (only required for photos copied since upgrading to Lion, everything from before the upgrade is fine anyway).
    Hope others find this helpful.

  • Sudden problem with importing tiff files with alpha channel (CS5)

    OK this is driving me nuts. For years I have been importing image files that have an alpha channel  into FCP as.tiff files. I use Photoshop files only when I want to use the layers as they are too cumbersome otherwise). I have recent upgraded Photoshop, etc. to CS5 and now FCP won't import them anymore. I get a message saying: "File error: 1 file(s) recognized, 0 access denied, 1 unknown"
    I am not doing anything different and tiff files created in just the same way in an earlier version of Photoshop import and work just fine. Is this a CS5 bug? Does anyone know of a work around. I want to keep using tiff files as they seem to work best for me with alpha channel work (and I don't see why I need to reinvent the wheel).
    Thanks
    A

    I've had a similar issue recently. Same TIFF files downloaded from the same server, different FCP project, new error. I either see"File error: 1 file(s) recognized, 0 access denied, 1 unknown" or I get the even stranger, "Unrecognized file type."
    I can open them in PS and save them again as TIF, same results. I know these are not CMYK files but even if resave the TIF as RGB, I get the same results, they are not recognized by FCP.
    But if I open them in PS and save them as PNG with alpha, they improt fine.
    I have no idea what's going on.
    bogiesan
    Message was edited by: David Bogie Chq-1

  • LR import with alpha channel

    <Lightroom novice> Can I import a tif image with a alpha channel in it? It seems as though LR will accept the image and allow development but when I export it as tif or psd it goes out as RGB only - the alpha channel is gone. I don't really "need" to do anything with this channel in LR but I can't have it disappear either. Maybe a import/export setting issue - I hope so...

    TLL... wrote:
    "All file "edits" are kept in LR's catalog, which should be backed up along with the unmodified "original" files."
    OK, got that too. We probably won't save this once the exported images are approved and backed up.
    It sounds like you don't need LR's database tools for organizing, adding metadata, or the various Export modules. You could still use LR to expedite Development editing of the RGB image. One possible solution is to Export the LR edited RGB images full size to a separate folder with the same bit depth and colorspace as the original files. Then use a PS Script to Batch Merge the LR export image to a new layer in the original file, something similar to this one:
    http://forums.adobe.com/thread/546727
    This way you still have the original RGB image backed up as a layer, which can also be unselected in the merge script.
    TLL... wrote:
    "At a later date the Alpha Channel information can be applied "non-destructively" in PS using editing layers to "blend" the IR image data."
    This is where I'm getting lost. Are you talking about stripping the 'original' alpha channel from the pre-LR image and inserting it into the LR processed RGB image via PS batch/script? That's my thinking as an one approach.
    "These PS modified files can be re-opened in LR and will now show the applied Alpha channel editing layers. Make any further edits you desire in LR and use the most appropriate LR module to "tailor" the output for your specific usage."
    No they won't, or do these steps involve only psd files w/alpha channels? The alpha channel (IR data) is still ignored by LR, I have no way to even just keep that information once inside LR nor can I "taylor" a way to save an image with 4 channels of color information inside LR.
    I have no idea what you will be doing with the Alpha channel IR image data, but I was suggesting to convert the Alpha channel to a layer mask in PS with 'Blending.' This leaves the Alpha channel as a backup of the IR data. Here's a simulated example using a an IR layer mask I created using LR's B&W IR Develop preset:
    You can use PS actions with the Batch processor and/or build scripts to do just about anything. In LR you can create Develop presets to apply adjustments across 1,000s of images with a couple of mouse clicks, but no Actions or scripting capability. Like I said, PS & LR are complimentary, but different. I'm not sure which processing methodology is best for your image "end-use" but I hope this gives you some more ideas.

  • Layered Photoshop files with alpha channels

    I wondered if anyone had a work around for the problem of layered PSD files with alpha channels not previewing properly in Aperture 3.1.1. I know it's been an issue in previous versions of Aperture but I thought Apple would have sorted this by now, or am I asking too much?

    I tested a file last night as follows:
    Sent file via 'Edit with Photoshop CS5' (as PSD 8-bit, sRGB color space) > changed background to normal layer > created circular selection around subject and inverted to remove most of image leaving transparent area (about 70% of image) > saved file > closed Photoshop > file updated in Aperture with black filling in the transparent area.
    Resent the PSD back to Photoshop (which opened correctly with transparent area) > created two new layers and sent one to background > filled new background layer with White and left top new layer transparent > saved again and closed Photoshop > file updated in Aperture with white showing in transparent areas (no black).
    AFAIK, this is how it is designed to work.
    My only other suggestion would be for you to create a new empty library (press Option while launching Aperture > Create New..) and then import one RAW or JPEG file and test.
    Note - you can reset Photoshop by holding down 'Command + Option + Shift' immediately after launching Photoshop and clicking 'Yes', then set the 'Maximize Compatibility...' to 'Always' again. Doing this prior to sending the file from new library would probably be best.
    Apologies in advance if you have already tried this and for outlining procedures that you are already familiar with (just not sure what level Photoshop user you are).

  • No Method of Batch Export for Clips with Alpha Channels?

    Good morning,
    As many a flustered editor has eventually discovered, in order for FCP to export sequences with alpha channels to a 32-bit format, the timeline has to be un-rendered at the time of export, or else the transparent parts will appear black in the outputted file. This sort-of makes sense if you know how FCP and render files work, but in a perfect world I think I'd have designed the export interface a bit differently. Now that I think about it, I'm actually working in an Animation (Millions of Colors +) sequence, so converting transparent areas to black makes no logical sense at all.
    Anyway, I have several sequences that I would like to export as 32-bit TGA QuickTime files, preserving their transparency. If I Export Using Compressor, the process results in pre-rendering of the sequence, turning the transparent areas black. The same problem occurs if I export QuickTime reference movies from FCP and open them directly with Compressor.
    Does anyone know of a way to avoid this silly phenomenon or am I stuck individually exporting each sequence from FCP, one...at.......a................time?
    Thanks,
    Zap

    Thanks, Andy, "Batch Export" eventually did the trick!
    I forgot about that tool because I've never actually had to use it before! After playing around with it for a while, I found that as long as the sequence settings for each sequence in the batch are set to a codec with an activated alpha channel, it works just fine.
    Thanks again,
    Zap

  • Using video with alpha channel

    I purchased a video clip from istock, the video clip is an .mov and has a alpha channel included.  The video clip is santa clause over a black background and tagged at the end is a white solid of the video (I assume this is the alpha channel)  How do I use the alpha channel to help key out the vidoe clip that I need.  here is a link to the actual video clip I purchased. http://www.istockphoto.com/stock-video-11011749-santa-claus-with-alpha-channel-ntsc.php
    Thanks Ja

    As Szalam said, the b/w image can be used as a luma matte.
    Also check if the actual piece of footage has an embedded alpha channel, i.e when you import it AE should know there is an alpha channel and let you know in the top of the project window when you select the element (or "interpret footage").
    Alternatively just drag the footage to a comp and enable the checkerboard background to see if there is transparency.  These three approaches are the same...just different ways of finding out about the alpha channel.

  • Question: Quick Look in Finder; problems with alpha channels

    Hi
    "Quick look" in Finder is great for quick presentations of a folders selected contents but it only works with images that contains no alpha channels or masks. Is there any way to work around this to display say PhotoShop documents with alpha channels? Or any plug-ins/applications that can help?
    thanks.

    This has been broken forever in OS X, and I don't know why, because it used to work just fine. I suspect the engineers did something to QuickTime that causes this problem, but it has been borked for so long I don't remember when the ability to correctly display files went wrong. I just remember that once upon a time all sorts of things from Apple worked correctly in displaying such files, but pretty much nothing does now. This includes the Finder, Preview, QuickLook, and various third-party image browsers that use Apple's own system level image handling abilities, such as VitaminSee or CocoaViewX. When I need to actually see what's there, I browse with Adobe's Bridge.
    Francine
    Francine
    Schwieder

  • How to render with alpha channel?

    Hello,
    I am trying to render a comp with alpha  channel QT PNG. When i play the clip it's with black BG but if i  imported in AE is with alpha channel. How to render in such way that i  can play in Quicktime without the black BG? Am i missing something?
     Thanks!

    robert_ro wrote:
    Hello,
    I am trying to render a comp with alpha  channel QT PNG. When i play the clip it's with black BG but if i  imported in AE is with alpha channel. How to render in such way that i  can play in Quicktime without the black BG? Am i missing something?
     Thanks!
    You've successfully rendered the alpha channel. Alpha information is not displayed as expected in some players. IN QT Player, your alpha is transparent but the player has no background so it defaults to black. Check the playback operations and settings/prefs for QT Player, there may be a way to tell it to show alpha information.
    bogiesan

Maybe you are looking for