Keep transparency of png image with type TYPE_BYTE_INDEXED

Hi, i have a problem with a few png images. they have the type TYPE_BYTE_INDEXED. if i do any resizing or anything else with Graphics2D the transparency is lost..
here is a simple example..
        BufferedImage bi = ImageIO.read(new File(args[0]));
        double w = 450;
        double oriw = bi.getHeight();
        double orih = bi.getWidth();
        double h = (oriw/orih)*450;
        Image image = bi.getScaledInstance(450, (int)h , bi.getType());
        BufferedImage biRes = new BufferedImage((int)w,(int)h,bi.getType());
        Graphics2D bufImageGraphics = biRes.createGraphics();
        bufImageGraphics.drawImage(image, 0, 0, null);
        System.out.println(biRes.getType());
        ImageIO.write(biRes, "png", new File(args[2]));my actual java program is more complex like this..
is there anyway to "rescue" the transparency?
p.s. sorry for my bad english ;)

Try something like this:
BufferedImage biRes = new BufferedImage(bi.getColorModel(), bi.getColorModel().createCompatibleWritableRaster(w, h), bi.isAlphaPremultiplied() , null);You have to copy the color table to the new image.
The transparency data is written there.

Similar Messages

  • Keep transparency of png image with type TYPE_BYTE_INDEXED(new duke stars)

    related to: http://forum.java.sun.com/thread.jspa?threadID=5178660&tstart=0
    opened to assign new duke stars

    Try something like this:
    BufferedImage biRes = new BufferedImage(bi.getColorModel(), bi.getColorModel().createCompatibleWritableRaster(w, h), bi.isAlphaPremultiplied() , null);You have to copy the color table to the new image.
    The transparency data is written there.

  • How do I get picture control to display PNG images with transparent background?

    I have an image of a robot arm looking from the top with a transparent background and saved as PNG. When I drag the image directly to LabVIEW front panel, the image shows properly with the transparent background, but I want to manipulate it such as rotate the image. I used the Read from PNG.vi to read the image to a picture control, but the background isn't transparent anymore. Am I missing something?
    Please help.

    unclebump gets 5 stars for referring you to a document that I wrote. 
    Incidentally, I wrote it years back, for LabVIEW 7.0.  A couple of notes to summarize:
    The picture control doesn't "really" support transparency.  However, the image data type supports masking, and stores the alpha channel, if present in your image data.  So you use the "Create Mask By Alpha.vi" referenced in that document to mask out pixels whose transparency is above a certain level.  It does not support partial transparency.  You could try to implement your own blending algorithm based on the picture control's current pixel values, and the image data's RGB value and transparency value, but it would probably be very slow.
    Also, that VI ships with 8.0 and later.  I don't know if it's on the palettes but it lives here:  vi.lib\picture\picture.llb\Create Mask By Alpha.vi
    Good luck!

  • Problem with reduction Of an PNG Image with transparent background

    I have an PNG Image on my computer with a transparent background that I would like to reduce 50% and save it back to my computer can you tell me how to achive this?

    Are you looking to reduce the size (pixel dimensions) by 50% or reduce the file size by 50%?
    If you want to reduce the actual image size (pixel dimensions) you could go to Image>Image Size
    and check resample image with constrain proportions and then enter 50 in the pixel dimensions at the top after setting
    the drop-down to percent.
    Or use file Save for Web and enter 50 under the percent under image size.
    As far as saving you could use File>Save As in photoshop and choose png or File>Save for Web>png
    (save for web usually results in smaller file sizes)

  • 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.

  • Safari on iphone won't render cgi generated png images with query strings

    I've got a cgi app functioning as a web service that generates png images and serves them up as part of another app which marshals them up in HTML.
    Here's the image stand alone:
    http://cybre.net/maps/mapgen.pl.png?WIDTH=1024&HEIGHT=768
    and here's how I marshal it:
    <IMG CONTENTTYPE='image/png' SRC='http://cybre.net/maps/mapgen.pl.png?WIDTH=1024&HEIGHT=768'>
    It seems to work on firefox, epiphany and galeon web browsers for linux, and my windows friends say that internet explorer renders them okay as well.
    My only apple hardware is my iphone, and safari pretends that there is no content when it renders the HTML page. Safari on the iphone does not render even using a direct link.
    The png is generated by perl mapscript, $img = $map->draw;
    print "content-type: image/png\n\n";
    $img->write;
    close(STDOUT)
    On the previous version of the iphone firmware, and before i factored the image generation out into a web service, the iphone was able to render the png image successfully.
    Is this safari wierdness where it gets cranky that there is
    QUERY_STRING info after the .png? mapgen.pl.png?foo=bar ?
    If so, are other browsers just being hyper liberal in what they accept and safari is playing by the rules or is this a bug in safari?
    thanks in advance,
    -marc

    it turns out that safari's handling of png is broken, the problem reproduced on both iphone and mac safaris.
    in changing the format to gif, it all works okay.
    does apple allow mortals to file bugs against safari?

  • Transparency in png image not showing

    Hello,
    I have a Region, which needs a background and an image 'on top' of it.
    I can set the background using
    setStyle("-fx-background-color: #" + 123456 + ";");
    Or I can just use a Rectangle of that colour.
    Then I have an ImageView...   spiralImgView = new ImageView(new Image("images/spiral2.png"));
    The png image itself has some transparency in it.
    So when I add them to the region...
    this.getChildren().addAll(rect, spiralImgView);
    I just get a white background showing behind the image.
    Can anyone help me fix this?
    Thanks

    I didn't do any coding.  This will tell you if it is your image:
    1)  Download and start JavaFX Scene Builder
    2)  Without making any changes paste "-fx-background-color: #1d1d1d;" into the "Style" box of the "Properties" window
    3)  Drag and drop an Image View into the scene from the "Library" window.
    4)  Click on the ImageView in the "Hierarchy" window.
    5)  In the "Properties" window Use the "Image" selector to find your img on disk
    If your image is mostly transparent it's background will not be white but #1d1d1d

  • No Transparency on PNG image problem

    I'm trying to create an ImageIcon that uses a transparent PNG image. I have set a particular colour on the image itself to be transparent in Corel PhotoPaint, and when i view the .png image that is output this colour is transparent.
    However, when i then load this png image into my Swing app, using it as an ImageIcon, the transparent colour is no longer transparent, and the original colour can be seen in its place.
    Anyone have any ideas?
    Cheers

    I'm trying to create an ImageIcon that uses a transparent PNG image. I have set a particular colour on the image itself to be transparent in Corel PhotoPaint, and when i view the .png image that is output this colour is transparent.
    However, when i then load this png image into my Swing app, using it as an ImageIcon, the transparent colour is no longer transparent, and the original colour can be seen in its place.
    Anyone have any ideas?
    Cheers

  • 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

  • Transparency not working on smartshape button filled with transparent (PNG) image.

    I'm using Captivate 8 and have had no problems so far importing PNG images with transparent backgrounds.....that is until I try and make a smartshape button and import a transparent PNG image as the background.
    It displays fine on screen, but whenever I preview it or publish, the white background of the image/button displays. Is this a known Captivate 8 limitation?
    Sorry if this is a repeated question....I've tried trawling through the forums and all I can see is to try different file formats for the images, such as GIF or BMP, which I've tried and nothing works.
    Any advice or suggestions?

    If it is a button, what is inserted for Rollover and Down state? I just recreated a shape button, with three different images for the states. All are in one PS-file as layers which I imported into Captivate. I kept Stretched checked in this case, because I know there is sometimes a slight change in size between states. Here are screenshots of Up, Rollover and Down state. The stroke was set to 0 for the shape, but to prevent all color contamination I also set stroke to the color of the background (light grey). In the first (Up) image you can clearly see where the stroke is due to truncation of the Question mark.
    Seems only possibility is in the creation of the PNG's? What was your work flow?

  • Images with transparent backgrounds in MDM

    I've got several images in MDM with transparent backgrounds, yet when i look at these in image manager (or thumbnails in data manager) they look terrible. The transparency is black for example, among other issues. These images are all okay in photoshop, they have been saved as .png and imported through the data manager.
    Has this import ruined these image files on the way in? When my search engines etc extract the images, what of the transparencies?

    Hi Adam,
    MDM makes use of Internet Explorer quite frequently. I can imagine that this engine is also used to display images in MDM. However, Internet Explorer in version 6 does not support transparency in PNG images. That is why the black background occurs.
    Since your images after upload are only saved in a binary object in the database, you should not encounter any data loss when using the same images. If you need to create variants, I would consider using Photoshop for the creation of those.
    I hope that helps you further.
    Best regards
    Christian

  • Black background for transparent PNG images - Xcelsius 2008 SP4

    Hi Experts,
    I am using Xcelsius 2008 SP4. I have used Image component to show a PNG image with transparent background. When I export the flash, the image is being shown with a black background.
    In Xcelsius 2008 SP3, this problem was not there. I am facing this issue after installing SP4.
    Did anyone else face similar issue ? Is there any workaround ?
    regards,
    pasg

    Hi all,
    I was facing the very same issue. I succeeded in finding a solution to it. This is happening coz of the dimension and pixels of the .png image. I imported the image in the image component, which had the dimensions, 175 x 70, and was of 9.26 kb and the black background was visible. I then changed the dimension of the image to 428 x 140, and 19.2 kb (double the size), and VOILA!! to my surprise IT WORKED !
    Don’t forget to “check” the “embed file” and  “Hide SWF Background Color” check boxes in the image component's, general tab.
    Try the same, I hope this helps.
    Regards,
    Sara

  • PNG Semi-Transparent background shows up with visual errors in code view in Dreamweaver CS5

    Hi,
    I am using an image as a visual divider between blocks of content for a template that I am making. The background is a PNG image with varying amounts of transparency. This background is set to be at the bottom of the div and creates a horizontal line. Everythign works out when the page is viewed in browser, and also in live-view inside dreamweaver. But once I view it in code view, the lines turn into jagged green distortions. I asked friends to run this in their dreamweaver and it is happening to them as well. Any help is appreciated. Thanks.

    I guess you're referring to 'Design View'.
    Design View is only more from a reference perspective - it doesn't render graphic elements the way it is supposed to, always.
    But, you did mention that it looks just fine in Live View, right?
    Btw, can you post the CSS rule you've applied to this DIV where you add the background image for the separator line?

  • Shrinking PNG Images

    Photoshop CS5, is not shrinking PNG images with transparency more then I would like. Including adjusting all options from 'save for web', does anyone have any recommendations or alternatives that I could use ?

    Reading between the lines, it sounds as though you need the transparency.  What's not so clear is whether you need the 256 levels of transparency, nor what your use for the images is.
    - Do you need partial transparency?
    - Are these images to be used on the web?  How?
    - Could something like using a specific background color over the top of a specific background substitute for transparency?
    - What kind of images are they?  Could they benefit from noise reduction, which will allow the data to compress better?
    The PNG format is the only one that's going to give you partial transparency and web browser compatibility.
    -Noel

  • Framing image with transparent background png frame

    hi,
    i'm trying to find a way to frame images with transparent background png frames...
    what i'm doing now is
    1-drawing my image on a panel
    2-creating a 2nd image using the frame's filename, stretching this 'frame-image' to a size slighlty larger than that of my main image and drawing the 'frame-image'
    the problems with this method are:
    1-depending on the width of the frame, the frame sometimes hides parts of the image (thick frame), and sometimes there is a gap between the frame and the image (thin frame).
    2-if the image file containing the frame is larger than the frame (Ex: The image is 300x300, the frame is centered in this image and is 200x200; as opposed to the image is 200x200 and the frame takes up all the space), when i position the 'frame-image' near the top left corner of the image i want to frame, the frame appears at the wrong place (shifted down and to the right). This is due to the fact that i'm placing the top corner of the created 'frame-image' and not the frame, who is not in the top corner of my 'frame-image'.
    Is there a way to do what i'm trying to do???
    My ideas (which i don't know how to achieve are)
    1-To 'analyse' my transparent background png file and
         1-only keep the frame,
         2-calculate the frame's thickness
    OR
    2-Let java do the analyzing for me and tell it to frame my image with the frame in the png file
    please feel free to ask for more explanations if my description/question is confusing,
    thanks.

    Have you looked into the Border interface? If what you really want to do
    is put a custom border on a component, you may be able to do it this way.
    Anyway, here is some code that stacks and centres 2 images. It's not hard to do.
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class Example extends JComponent {
        private BufferedImage backgroundImage;
        private BufferedImage foregroundImage;
        public Example(BufferedImage backgroundImage, BufferedImage foregroundImage) {
            this.backgroundImage = backgroundImage;
            this.foregroundImage = foregroundImage;
        public Dimension getPreferredSize() {
            int w = backgroundImage.getWidth();
            int h = backgroundImage.getHeight();
            return new Dimension(w, h); //assuming this is bigger
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            int w = getWidth();
            int h = getHeight();
            //paint both, centred
            int x0 = (w-backgroundImage.getWidth())/2, y0 = (h-backgroundImage.getHeight())/2;
            g.drawImage(backgroundImage, x0, y0, null);
            int x1 = (w-foregroundImage.getWidth())/2, y1 = (h-foregroundImage.getHeight())/2;
            g.drawImage(foregroundImage, x1, y1, null);
        public static void main(String[] args) throws IOException {
            URL url1 = new URL("http://weblogs.java.net/jag/Image54-large.jpeg");
            URL url2 = new URL("http://weblogs.java.net/jag/DukeSaltimbanqueSmall.jpeg");
            JComponent comp = new Example(ImageIO.read(url1), ImageIO.read(url2));
            final JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(comp);
            f.pack();
            SwingUtilities.invokeLater(new Runnable(){
                public void run() {
                    f.setLocationRelativeTo(null);
                    f.setVisible(true);
    }

Maybe you are looking for

  • Wrong Depot Excise Invoice Number Ranges

    Hi, We have created the new number ranges for the year 2010 for Object - J_1IDEPINV(series group S11) But when the Depot excise invoice is created by using J1IJ with reference to delivery, the number ranges are picked from old series of 2009. The Del

  • Making a DVD from iMovie 8

    I have read some of the earlier posts and replies, so I think I know some of the answers to my question (and I'm not encouraged). I have made an hour long movie in iMovie 8 based on video taping I did for business using miniDV. I need to make a DVD o

  • Adding more RAM to my Pro Mac - config?

    Hello folks, I'm considering buying from OWC (one-third the cost of buying from Apple) - 8GB (2GBx4) PC5300 DDR2 ECC 667MHz 240 Pin FB-DIMMs. Specifically: 8.0GB OWC Matched Set (2GB x 4) PC5300 DDR2 ECC 667MHz 240 Pin FB-DIMM Modules for all Mac Pro

  • Show indices of Last TWO buttons pressed in a boolean array (how to?)

    How would you go about showing the indices of the last TWO buttons pressed in an array of buttons, and only after TWO buttons have been pressed? I know how to show the LAST button pressed, and I know how to flag the event of two buttons being pressed

  • How to migrate my oracle forms 9i and reports application..

    Hi, we have this budgeting application developed in oracle forms 9i,reports integrated in oracle portal. Now we have to move this application from oracle 9i to oracle 10g and have to integrate it with new portal again. Can anybody pls help me how do