Transparency with png file

Hello,
I created png file in Corel Draw (its simple logo in two colors) and save it with some transparency. What I want to do is: load it in java and put it into my program. Easy. But the problem is, that the transparency doesn't work.
I'm using this code:
     private void init() {
          try {
               img = ImageIO.read(getClass().getResource(source));
          } catch (IOException exc) {
               JOptionPane.showMessageDialog(null,exc.getMessage());
      * Default paint method for this component.
     public void paint(Graphics g) {
          g.drawImage(img,0,0,null,this);
     }Where source is "/logo.png"
It is simple "component" which I'm simply adding it to ContentPane in my applet.
Any ideas? Thanks.
A. J.

Well,
in that case I don't understand where is problem. As I mentioned above I've created image in Corel Draw. After that I exported it to .png file. During exporting I set the white color to be transparent. After I saved it I checked the image in Gimp, where that color was transparent. So I'm presuming that the image is all right.
I've read something about alpha value in pictures. I'm not sure if I don't confusing this two things together...? So I'd like to explain what I'm trying to do.
I have picture (logo) with two colors, blue and white. I wan to to draw it in my applet as only blue logo onto background.
Here's my code:
public class Logo extends JComponent {
     private BufferedImage img;
     private String source = "/logo.png";
      * This method initializes this component.
     private void init() {
          try {
               img = ImageIO.read(getClass().getResource(source));
          } catch (IOException exc) {
               JOptionPane.showMessageDialog(null,exc.getMessage());
     public void paintComponent(Graphics g) {
          g.drawImage(img,0,0,null,this);
      * Default constructor.
     public Logo() {
          init();
     public Logo(String source)
          this.source = source;
          init();
     }After that I want to put this logo into my applet. I'm using this code:
      * This is the default constructor
     public Java_applet() {
          super();
      * This method initializes this
      * @return void
     public void init() {
          this.setSize(670, 500);
          this.setContentPane(getJContentPane());
     private JPanel getJContentPane() {
          if (jContentPane == null) {
               jContentPane = new JPanel();
               jContentPane.setLayout(null);
               jContentPane.add(getLogo(),null);
          return jContentPane;
     private Logo getLogo() {
          if (logo == null)
               logo = new Logo();
          logo.setLocation(new java.awt.Point(0,0));
          logo.setSize(new java.awt.Dimension(670,50));
          return logo;
     }I hope now it's more clear what I'm trying. Thanks for any ideas.
A. J.

Similar Messages

  • IE6 problems with PNG files (no, not transparency)

    For some reason, although all the images seem to appear just
    fine, IE6 keeps
    acting like it can't finish loading the two PNG files on the
    page. It just
    hangs at the last byte, it seems. I can leave the browser for
    an hour and
    I'll still come back to a status bar indicating 1 file
    remaining, *.png
    (even though that file is visible and fully loaded
    on-screen).
    http://www.vilverset.com/mark.html
    It's like IE6 can't "close the connection" on PNG files once
    it's opened for
    download.
    It more than likely has something to do with the attached
    pngfix.js file to
    enable alpha channel filtering in IE6. But since Murray
    recommended this
    specific fix, I won't go out looking for another one. There
    might just be a
    typo somewhere causing this.
    Thanks.

    InDesignSecrets » Blog Archive » Eliminating YDB (Yucky Discolored Box) Syndrome
    And .png isn't really a print format...

  • Indesign CS5 with PNG file exporting as a PDF file but the text is random bold

    Hello,
    I am looking for help to teach me how to solve this problem.
    I use Indesign CS5 to make a proposal. I set the page marker and sub title in the master page.
    Of course, there are including dozens of pages and some pictures here.
    And one of these page, I place a PNG file and type some text.
    When I export this file as a PDF file, one page, which is including PNG file, the text becomes random bold.
    Therefore, I have used PSD file to cover the PNG file. But finally getting the same problem.
    So does anyone can help me how to solve this problem?
    Thanks so much for your help.

    This sounds like a known issue with transparency on the page. When transparency is introduced ID uses a differnt method, apparently, of rendering text on that page and it appears bolder on screen and can print that way on low resolution devices like desktop printers. It usually is not a problem on press output.
    The only way to mainatian consistency would be to introduce transparency on all pages, perhaps by adding a transparent object to your master page.

  • Animation with .png files - from Maya 3D

    I need to import an 3-second animated sequence (created in Maya 3D by someone else) into FCP Studio sequence.
    I have been given a folder with 90 .png files. Is there quick/easy way to do it?
    The individual .png files open up fine.
    They only have experience with premiere, and thought I should be able to import it as sequence?
    Any suggestions? Do I force them to output as .mov file? They don't know if they can preserve alpha channel (we need to keep background transparent).
    Thanks for any suggestions or help!

    The iPad expects the photos to be in a folder named DCIM, and have names 8 characters long plus the extension. i.e. image001.png
    Do your png files meet this criteria?

  • Problems with .png files when printing

    Hi,
    When sending my InDesign document to print (from exported pdf's)
    some of my .png files are showing up with semi transparent boxes
    of a different shade than the surround. This reflects the size of the files.
    On screen these discrepancies are not apparrent.
    Where does this problem lie? In the way I have made the .png's?
    Or a setting in InDesign?
    Or with the printer?
    Any suggestions welcome,
    Thanks
    Nik

    InDesignSecrets » Blog Archive » Eliminating YDB (Yucky Discolored Box) Syndrome
    And .png isn't really a print format...

  • Best way to work with .png files for print

    My client suppllied 100 color .png files (screen captures), about 1700 pixels wide for his book. I opened one with Photoshop, saved as Tiff, converted to Grayscale, cropped to 300 dpi and placed in InDesign, but the InDesign file size is almost 2mb. Is there a better method?

    That’s not what I mean at all…I mean what ever they are, they are. Just place them and be done with it.
    There is nothing you can do with them in Photoshop that will make them better.
    And you are incorrect…the fact that one page document is 2 megs does not mean the full document will 200. Graphics are linked, not embedded, by default.
    Do not embed them.
    I’m going to move this thread to the InDesign forum.
    Bob

  • Trouble with png files converting to pdf

    Why are my files getting all distorted when I convert a png file to pdf?

    best of luck, david r.
    Hi Donald and David,
    Thanks to you both for the ideas. Peter at SONiVOX technical support has been trying to help solve this also. He just sent me an email with an idea that solved the issue!
    He suggested I change the length of the SF2 file names to abbreviated names - as the ones included were long (see above in OP).
    These samples sound great in the EXS ... really very nice - and dry enough to be very usable in a variety of scenarios I am thinking. I will try their horns next.
    And Sonivox technical support is great if anyone is thinking about trying them out. Fast and approachable. They go above and beyond the support we are used to with some third party companies.
    Again thanks for this.
    Cheers
    Dee

  • Permanently removing part of an image from a transparent background png file

    Hello, I think I know the answer to this question, but I wanted to double check.  I am new to Photoshop and do not know all the functions.  I have a png transparent background file of a tree with a lot of branches.  I want to erase some of the branches so they are just permanently gone.  I would like to use this image on different backgrounds so I am looking to just erase the branches all together.  Is this possible?  If not in Photoshop, perhaps another adobe program?  Thank you!

    If you want to permanently delete the branches then you can just erase them using the eraser tool. I would always suggest keeping the original file just in case something goes wrong and you want to start again. So just open the .png, save a new version and start erasing the branches you want.
    Simple video:

  • Transparency with *png in MHP with DVBAlphaComposite-what's the problem?

    Hello!
    I know this topic exists already, but it could not help me with my problem:
    I want an HIcon with an transparent picture in it but I am not able to get any transparency..To me that code seems to be right,
    but when testing it with the IRT RI, the Graphic is opaque..
    Does anybody see what i am missing?
    public void startXlet() throws XletStateChangeException {
    MediaTracker tracker = new MediaTracker(this);
    picture = Toolkit.getDefaultToolkit().getImage("AlphaGrafik.png");
    tracker.addImage(bild, 0);
    try{
    tracker.waitForAll();
    catch(InterruptedException e) {
    picture = null;
    cont = new HContainer(0, 0, 720 , 576);
    icon1 = new HStaticIcon(picture, 0, 0, 720, 576);
    cont.add(icon1);
    scene.add(cont);
    scene.setVisible(true);
    icon1.requestFocus();
    public void alpha(Graphics g){
    DVBAlphaComposite compositeRule = DVBAlphaComposite.getInstance(DVBAlphaComposite.SRC_OVER, (float)0.5);
    DVBGraphics image = (DVBGraphics)g;
    try {
    image.setDVBComposite(compositeRule);
    catch (org.dvb.ui.UnsupportedDrawingOperationException ex) {
    System.out.println("Exception: " + ex);
    image.drawImage(picture,0,0,null);
    Any help is very useful for me!
    Regards, Alex.

    I have simular problem applying alpha composing to Graphic layers.
    If I draw graphic elements like circle or rectangular with some color or draw images with transparency (Alpha) then I can see only background IFame under top element. It seams when I draw something on graphic layer then middleware compose background video layer and DVB colors of element that I am drawing at the moment. Colors of elements that placed under the top element are ignored. I tried verious composing rules but It does not give any correct result. It seams middleware does not suppot alpha composing at this moment. Did you get some exception applying alpha composing?
    I use Alticast MHP middleware installed on my Humax STB

  • Transparency in png file

    How can I make the shadow of this piece of paper transparent in a png so i can make the shadow transparent on the web?
    I know how to make a fake, photoshopped drop shadow like this on a png:
    but I'm trying to figure out how to make just the shadow of a paper scan transparent/multiplied so it looks more real, and so I can put a background image behind it. i feel like it has something to do w/ making a clipping path, and putting the shadow on an alpha layer, but i can't quite figure it out.
    thanks!

    You are on one right track.
    My recommendations:
    • Load the luminance of the composite channel by command-clicking it in the Channels Panel
    • invert the Selection (command-I)
    • create a black Solid Color Layer (Layer > New Fill Layer > Solid Color)
    • drag that behind the layer with the image
    • create a Path that hugs the paper
    • apply that as a Vector Mask to the paper Layer by command-clicking the »Add a mask« button at the bottom of the Layers Panel (third from the left)
    Now there may be a slight problem with the edges, especially of the shadow Layer – you may have to brush or clone stamp there to get a perfect fit to the paper.
    And if some regions of the Layer Mask that are supposed to be transparent are less than 100% use Curves or Levels or even the Burn Tool to rectify that. (To view the Layer Mask alt-click the Layer Mask icon in the Layers Panel.)

  • Creating semi-transparency without PNG files

    Hi I have designed a logo for a friend and he needs to upload it onto a companies web site. They have said that it must be either Jpeg or Gif. However, since there is some semi-transparency in my logo a Gif file wont allow this and a Jpeg wont create any transparency. They wont allow PNGs. I have tried to find out what colour the website background will be so I can simply put the logo in a box of the same colour but apparently he is not able to find out this info.
    Is there any other way of getting around this?

    Can you change the logo so the gradient goes to a solid color instead of transparency?
    The very use of gradients at all is relatively new to the world of logo design. When UPS redesigned their logo several years ago there was a huge uproar in the community of the use of gradients ( see: http://www.dinesh.com/images/stories/logo/worldfamouslogos/ups_logo.jpg ).
    I don't think I've ever seen a logo that uses alpha transparency though, due to the exact problem you're having.
    Look at some of the samples on this site, perhaps it'll spark a creative idea that'll help you fix the problem:
    http://logopond.com/gallery/

  • 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);
    }

  • CS3: PNG File Type Problems

    I can import PNG files without a problem, but when i drag one
    onto the
    stage, it is always a very small size and not the size it
    should be. JPG
    and GIF, etc don't do this. If I drag one onto the stage from
    the library,
    they are the size they should be, but not so with PNG files.
    I can change
    the size in the property inspector just fine and the image
    will appear as
    crisp and clear as it should. But why is this happening?
    Thanks
    Aziz Peregrino-Brimah
    Bezworks Design
    www.bezworks.com

    The files being imported into Flash are files that I first
    exported out of
    Photoshop. If I export a jpeg file from photoshop and into
    Flash, there is
    no problem, but then I don't have any transparency.
    Aziz Peregrino-Brimah
    Bezworks Design
    www.bezworks.com
    "Aziz" <[email protected]> wrote in
    message
    news:f5jiam$sui$[email protected]..
    >I can import PNG files without a problem, but when i drag
    one onto the
    >stage, it is always a very small size and not the size it
    should be. JPG
    >and GIF, etc don't do this. If I drag one onto the stage
    from the library,
    >they are the size they should be, but not so with PNG
    files. I can change
    >the size in the property inspector just fine and the
    image will appear as
    >crisp and clear as it should. But why is this happening?
    >
    > Thanks
    >
    > --
    >
    > Aziz Peregrino-Brimah
    > Bezworks Design
    > www.bezworks.com
    >
    >
    >

  • Photoshop CC saves PNG files bigger than some PNG-specific tools

    Hey,
    as a web-developer i'm working with PNG files alot. Since the release of Photoshop CC i always need to go back to CS6 for saving what i did in CC. I thought maybe it's just an early bug which will be fixed soon but still nothing and annoying. Maybe i missed something and there is a benefit in this bigger files? So here is a short discription...
    When saving a PNG file
    ( file > save as > PNG > Compression: Smallest/Slow and Interlaced: None )
    the files saved in Photoshop CC are about 17kb bigger compared to the saving in Photoshop CS6
    A former 0,3kb PNG file gets saved with 17kb in Photoshop CC.
    I use the English Windows 64bit Version of Photoshop CS6 and CC.
    A fix would be very appreciated.
    Screenshot of both files:
    Thanks,
    Bye!

    Chris and Idothings:
    Here's a quick example that explains what I am talking about:
    Download this 32bit png, and open in Photoshop:
    http://www.estructor.biz/testje/heading.psd
    In Photoshop, the only options in the save for web dialog I have for png are these:
    and
    Since I require the alpha channel to remain intact, I am forced to export to a 32bit png (png-24 with transparency checked). Png-8 would be a much better choice, since this image could be optimized with a limited colour palette, but Photoshop does not allow a full alpha channel to be included in that case. In short, a pixel's transparency is either on or off in 8bit png mode.
    In Photoline I can choose a png with 32768 colours and full alpha transparency. This reduces the file size while I retain full visual quality.
    Fireworks offers us an additional option:
    Png 8 bit with Alpha Transparency. This gives us the power of full transparency and a limited index-based colour pallette. It also results in a much reduced file size.
    Unfortunately, Fireworks' colour reduction algoritms are quite old, and you cannot really choose 128 colours: it wrecks the quality (in this case, at least). With manual colour choices this could be improved, but the time this would take kinda defeats the purpose of having a web optimization tool.
    One other disadvantage to Fireworks: no further development. Adobe killed it.
    Often 256 indexed colours are not enough. Color Quantize goes one step further, and allows for a limited colour palette of 512, 1024, 2048 and 4096:
    This gives a web front end developer an incredible control over a limited colour palette, and yields the best balance between file size and visual quality, while retaining a full alpha channel. Color Quantizer also includes a very simple quality mask brush tool to paint over areas that must remain identical in quality.  The colour reduction algoritms are top-notch, so with the sample image even 128 colours are visually quite acceptable.
    Final results:
    Photoshop: full 32bit png - 254kb
    Photoline: 32768 colours 32bit png - 207kb
    Photoline: 256 colours 32bit png - 170kb
    Fireworks: 256 colour 8bit png + 8bit alpha channel - 54kb
    Color Quantizer: 256 colour 8bit png + 8bit alpha channel: 50kb
    Color Quantizer: 128 colour 8bit png+ 8bit alpha channel: 41kb
    Do I really have to explain any further? You'd have to be mad as a hatter to continue to use Photoshop for png optimization once you start to realize how limited its png output options are. Luckily, Color Quantizer (and ImageAlpha for mac) is completely free: so export to a 32bit png, and optimize in those.It will save a LOT of bandwidth.
    Chris, you are correct in stating the png export options have not changed since v5.5 - it shows. Photoshop is stuck in the nineties as far as web export is concerned.
    Oh, and one more thing: Photoline, Color Quantizer and ImageAlpha offer a wealth of dithering algoritms. While Photoshop users are limited to diffusion, pattern and noise, in Color Quantizer I have six different options plus other options to control the final colour reduction.
    PS I could not check ImageAlpha for the mac, since I work on a WIndows machine at home. In my classes I do demonstrate ImageAlpha to the students, and it gives comparable results to Color Quantizer (since both use, I believe, the same colour reduction algoritms) at a low 128 colours. I recall a file size of around 46kb.

  • Images sequence with png problem

    I created an image sequence with png files for transparency reasons. When I activate the interactivity, the original placed image shows behind the image sequence as i interact with it. Anyway to get this to go away other than hiding the intial image?

    nope. Transparency isn't well supported in image sequences.
    —Johannes

Maybe you are looking for

  • Cannot boot after a migration to systemd in OpenVZ

    EDIT: I "solved" my problem, and I doubt this thread will ever help anybody. You're warned. Hello, Earlier today, my Arch install that was still running with initscripts (and without the last filesystem/bash upgrade) suddently rebooted, and that brok

  • Firefox and printing selection

    Is there a way to enable selection printing in Firefox? I mean the process where one first highlights a part of the text on the page with mouse and then, in the print dialogue, chooses to print the selection. In FF 3.5 I can only choose between all o

  • Shared Photo Stream won't work

    I am trying to create a Shared Photo Stream with my iPad.  I have successfully followed available instructions to the point of inviting my wife to subscribe to the Photo Stream and having her subscribe.  The problem arises when the Shared Photo Strea

  • Code Written In Servelet Is Not Working

    1. My name is Anand Patil, I have developed a web project with my partner. 2. We both are using Tom Cat 6.0. And eclipse Juno as a IDE 3. My partner is using operating system Windows 07 and I am using operating system Windows XP. 4. All project files

  • Leopard 10.5.2 upgrade error message

    here is the error and chain of events that have been happening consistently for weeks. 1. Mac OS software update automatically informs me that there is new software to be downloaded. 2. Upgrade to Leopard 10.5.2 recommended. 3. I click upgrade, enter