Black background when scaling images with transparent background

I am implementing Zooming functionality for reports which have some icons. I am trying to scale icon by scaling its image. But the problem I am facing is that the icons have transparent background and the scaling puts a black background in place of transparent. Is there any way to maintain its transparency or better yet, Is there anyway to put a white backgound instead of the black one that is created by default ? Here is my code
     public static Icon getScaledIcon(Icon icon){
         if(icon instanceof ImageIcon){
              Image outImage = ((ImageIcon)icon).getImage();
                  return new ImageIcon(getScaledImage(outImage));
         }else{
              Image outImage = new BufferedImage(icon.getIconWidth(),
                        icon.getIconHeight(),
                        BufferedImage.TYPE_INT_ARGB);
                JComponent comp = new JComponent(){};
                icon.paintIcon(comp, outImage.getGraphics(), 0, 0);
                return new ImageIcon(getScaledImage(outImage));
    public static Image getScaledImage(Image image){
         image = image.getScaledInstance((int)(image.getWidth(null) * getScale()),
                       (int)(image.getHeight(null) * getScale()), Image.SCALE_SMOOTH);
        return image;
    }I haven't done much image manipulation , so I would really appreciate any help or advice.

I have also not done much of image work. But I guess you could achieve your functionality of showing scaled image in the screen by not scaling the image and show it, instead scale the image in paint method by calling g.drawImage giving the height and width. But use high resolution images so that scaling is good.
If you do in this manner, you could give any colour you want as background to fill the transparent area or leave it as such.
Regards,
techece.

Similar Messages

  • Image with transparent background als foreground of a button

    I'd like to build an app with buttons using the phone's accent Color as Background and an Image with transparent Background as foreground of the button. It should look like the tiles on the start screen of WP8.1.
    The following code doesn't work (no foreground appears)
    <Button x:Name="myButton" Background="{ThemeResource PhoneAccentBrush}">
     <Button.Foreground>
         <ImageBrush ImageSource="/Assets/myImage.png"/>                    
     <Button.Foreground>
    </Button>
    Are there any ideas?
    Thanks
    Martin

    Hi mfv_technet,
    The Foreground property is used to get or set a brush that describes the foreground color. So we can not bind the Foreground to a image,
    if I do not misunderstand you, in my mind if we want to set the button look like the tiles on the start screen of WP8.1, maybe you can try to refer to the following xaml:
    <Button x:Name="myButton" Foreground="Red" Background="{ThemeResource PhoneAccentBrush}" Margin="116,136,0,363" Width="195" Height="141">
    <Button.Content>
    <StackPanel Orientation="Vertical">
    <Image Source="/Assets/myImage.png" Width="80" Height="80"></Image>
    <TextBlock Text="Button"></TextBlock>
    </StackPanel>
    </Button.Content>
    </Button>
    The result:
    If I have misunderstood you, please feel free to let me know.
    Best Regards,
    Amy Peng
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Printing Images with Transparent Background

    Sorry if this question has already been asked, but I couldn't find anything similar to it in a search through the archives.
    I have a couple of images with transparent backgrounds in a document, much like the shells and the blue flowers in the "Classic Brochure" template in Pages 2.0.1. These images show up perfect on the screen, and when printed as .pdf files, but when I print to either an hp color laserjet 4600 or an hp laserjet 1320, the images show up with a clear box around them; the colors under the box (where it should be transparent) are faded and slightly blurred. This happens both with my document, and the unaltered "Classic Brochure" template. I've tried moving various objects backwards and forwards, but it doen't seem to have any effect. It even happens with one of the text boxes I have in the document.
    Another odd thing is that the printed "box" isn't the same size as the box that appears when you click on the object in the document. It's a bit bigger. I've seen other posts about problems with hp printers, but I'm not sure it's related. Any insight would be appreciated.
    MAF
    iMac Intel Core Duo   Mac OS X (10.4.7)  

    http://indesignsecrets.com/eliminating-ydb-yucky-discolored-box-syndrome.php
    Bob

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

  • Image with transparent background changes surrounding fill color when PMS...

    Hello.
    I have a .PSD image I'm using in InDesign CS3. It's a greyscale image with a transparent background. When I bring it into InDesign and set the background color of the image box to a Pantone and then print it, the PMS color within the area of the .PSD image size changes color compared to the rest of the page. But, when the same document is printed, but with "All Spot to Process" via the Ink Manager, the page prints fine. I get the same results on a number of different Canon and Xerox proofing printers. I have uploaded a PDF to my web server showing an example of the results I'm getting the PDF can be found here:
    http://theboyk.net/temp/PMSvsCMYK.pdf
    The first page is the document printed normally. You can see the color change in the green (Pantone Green). The second page is the same document printed with "All Spot to Process" via Ink Manager.
    Does anyone know why this happens when I leave it as printing a spot color?
    Any advice would be appreciated!
    Thanks,
    Kristin.

    I totally forgot to put that in my post.  Yes, I am putting logos with transparent backgrounds in front of colored rectangles.  That's how I noticed that this one logo is showing up with a white background.  The weird thing is that the other two logos are fine.  I did find a different version of this logo and this one works fine.  The one that works fine is a JPG and the one that shows up with a white background is a JPG.

  • 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

  • Image with transparent background shows up with a white background in ID

    Amateur needs help.
    I have a copy of a logo with a transparent background.  I made the (white) background transparent in PS by creating a layer from background and then selecting the white color in the background and deleting it.  This has always worked in the past.  But when I place this image into ID, it shows up with a white background.  I have tried saving as a PSD, TIF, JPG, etc.  I cannot get it to work. 
    I normally research these things until I find an answer, but I am on a tight deadline.  Thanks!

    I totally forgot to put that in my post.  Yes, I am putting logos with transparent backgrounds in front of colored rectangles.  That's how I noticed that this one logo is showing up with a white background.  The weird thing is that the other two logos are fine.  I did find a different version of this logo and this one works fine.  The one that works fine is a JPG and the one that shows up with a white background is a JPG.

  • Images with transparent background layers

    I have a number of .psd files with transparent backgrounds. If I import them into Aperture, they show up in the Browser and Viewer with black backgrounds. If I drag them into a Book, some of them behave as though transparent, but some retain the black background.
    I can't see any difference in the files themselves. They were all created by the same means. Why would some of them lose their transparency in Aperture and some retain it?

    Aperture doesn't support transparency at this time.
    I'm pretty surprised that any of them behave as though transparent.
    You should make the Image backgrounds the same color as the book pages to achieve a transparency effect.
    DLS

  • How to insert image with transparent background?

    I have several logos saved at .GIFs with transparent backgrounds that I would like to import into my dashboard, but it seems that the image component only supports JPEG.  Is there a way to import images while maintaining their transparency?

    Well, you CAN insert GIFs or other image formats.  But I have yet to figure out a way to take a GIF with a transparent background and import it into my Xcelsius while preserving the transparency.  The transparent background always just defaults to white.
    This is a crucial feature as I have some logos I want to use that are circular.  But if I can't give them a transparent background, it drastically limits their placement options.
    I know that flash does support transparency, so am I missing something here?

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

  • Using images with transparent backgrounds

    Hello. I'm trying to design several forms using a large background graphic along with several other overlays (defined by the form user) that contain transparent backgrounds. Unfortunately, everytime I go to change the graphic, the program won't recognize the transparency of the overlay and substitutes white in it's place. So, for example, I have a background image that is rectangular and when my form user selects an overlay that is circular, it inserts the circle with a white background (which is supposed to be transparent). Can anyone help me with this?
    Thanks!
    -Mike

    Min required version of flash player for my application is 9..
    I think I figured it out, Here is my solution:
    private function completeHandler(evt:Event):void
       var originalWidth:int=loaderG.content.width;
       var originalHeight:int=loaderG.content.height;
       var scale:Number = 0.5;
       var matrix:Matrix = new Matrix();
       matrix.scale(scale, scale);
       myBitmapDataObj=new BitmapData(originalWidth, originalHeight, true, 0xFFFFFF);
       myBitmapDataObj.draw(loaderG.content, null, null, null, null, true);
       var copyBitmapData:BitmapData= new BitmapData(originalWidth* scale, originalHeight* scale, true, 0x000000);
       copyBitmapData.draw(myBitmapDataObj, matrix, null, null, null, true);
       var myBitmapG:Bitmap=new Bitmap(copyBitmapData,PixelSnapping.AUTO,true);
       addChild(myBitmapG);
    I also try blur filter on my bitmap:
    var blur:BlurFilter = new BlurFilter();
       blur.blurX = 1.4;
       blur.blurY = 1.4;
       blur.quality = BitmapFilterQuality.HIGH;
       myBitmapG.filters = [blur];
    Or is there better solution?

  • Help! Trying to import image with transparent background

    I'm trying to import a picture that has a transparent backgound so when i layer it over video its just the picture itself not the canvas it was made on.
    In photo shop I made it on a transparent canvas.
    Whats my next step?

    Thank you.
    I have made my image with a transparent background in photoshop, now I need to bring it into final cut pro maintaining that transparent background, so I can layer it on video.
    How to I do this?

  • Photoshop Image with transparent background - exporting gives me a white background ?

    Hi,
    OK, hours of my life have gone into this one already - I guess that's computers!  I have some images in Photoshop which already have transparent backgrounds, however when I try and drag these into a different program, they move across with a white box as their background.  I have tried saving as TIF, GIFF ... - all sorts, so I am clearly missing a pretty fundamental step that I can't see.
    Any help would be SO appreciated.
    Thanks.
    Doreen.

    Save as PSD or PNG, depending on whether you final output will be print or web. Then use Place instead of dragging the image over.

  • Saving image with transparent background for web/Dreamweaver

    How do I save a little image, so that the background stays transparent. I already have the image set up in Photoshop with a transparent background and have saved it as gif and png. When I import it into Dreamweaver the background stays white instead of transparent. What am I not doing right, since I read several posts saying that png and gif are the right formats to save in, if you want a transparent background?
    Thanks for any help with this,
    Anne

    Well now that you have told me to save with some sort of an alpha channel, it works perfectly.
    In CS5:
    Select layer,"Composition,Make movie". Then navigate to "Output module" and choose an option that has "alpha channel" in the title.Choose a name for your project "Output to". I now use "lossless alpha".I don't know if that is the best one, but it seems to be working fine.
    There is no "Quicktime" option in CS5 as in older versions of AE.
    I was trying to save as a video in general or for photoshop and that just wasn't working out well.
    I don't know what the "Frames to Layers import assistant" is that you mentioned though. I still tend to drag and drop, rather then import.
    Thanks for your help.

  • Image with transparent background CS5 to A3

    I have clipped an image in PS and put it on a transparent background and reduced the image to 600 pixels high. I saved it as a png with "web and devices." When I import it into my A3 library it has some rubbish on the background. Adobe forum (an employee plus others) tells me that A3 has trouble with transparency. Help would be much appreciated. Thanks, jp
    Lefthand photo: image previewed in PS "web and devices" Right hand photo: Same image after being imported into A3 library.

    Thanks loads Bob, just as you posted that, i found that link on another thread and came back to post it and you beat me to the punch! So thanks loads!
    So if my printer is going to print this catalogue in litho print, rather than digital, do i still have to go back and flatten etc ?? I've separated the catalogue off to 108 individual pages with bleeds etc and it looks like I've got a fun friday night opening each one of them !!! rats!!
    thanks loads, kind regards,
    Charmaine

Maybe you are looking for