简体   繁体   中英

Java : Saving uploaded png image

I am having issue when i save a png file uploaded by user . It loses its transparency . Here is how I save it .

 ServletFileUpload upload = new ServletFileUpload(factory);

        ProgressListenerImpl listener = new ProgressListenerImpl();
        UploadProgressBar uop = new UploadProgressBar(listener);

        List<FileItem> fileItemsList = upload.parseRequest(request);

        for(FileItem fi : fileItemsList) {
///get name etc.
    File fNew= new File(fileLocation, justName);
            fi.write(fNew);
        }

it puts a black background . Any other way to save it as png ?

If you're creating a BufferedImage on the server side, make sure you create it as a type that supports the alpha channel, eg

BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

Paul

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM