Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

how to download and save transparent png file

Thread view: 
Alex - 02 May 2006 21:22 GMT
Hi all,

I'm trying to download and to save a transparent png file.
I succeed to download and save it, but in losing the transparent
background!

My source code is:
String url = "http://..../test.png";
URLConnection connection = new URL(url).openConnection();
Image image =
Toolkit.getDefaultToolkit().createImage((ImageProducer)connection.getContent());
ImageIO.write(toBufferedImage(image), extension, new
File(filename).getCanonicalFile());

with the function:

    private BufferedImage toBufferedImage(Image image) {
        if( image instanceof BufferedImage ) {
            return ((BufferedImage)image);
        } else {
            image = new ImageIcon(image).getImage();
            BufferedImage bufferedImage = new
BufferedImage(image.getWidth(null), image.getHeight(null),
BufferedImage.TYPE_INT_RGB );
            Graphics g = bufferedImage.createGraphics();
            g.drawImage(image,0,0,null);
            g.dispose();
            return (bufferedImage);
        }
    }

If someone have an idea for me?

(Is it possible to download and to save the getcontent() directly to a
file without transform it into Image?)

Thanks

Signature

Alex

Steve W. Jackson - 02 May 2006 21:40 GMT
> Hi all,
>
[quoted text clipped - 34 lines]
>
> Thanks

Since URLConnection includes a getInputStream method that returns an
input stream for reading from the connection, it seems logical that you
might test whether you can simply read byte-by-byte and then just write
the result to a local file via an output stream.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.