Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1071229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:41:09+00:00 2026-05-16T20:41:09+00:00

like this gif image it has transparent background, when i using ImageIO.write(image,jpg, file) to

  • 0

like this
gif image

it has transparent background,

when i using ImageIO.write(image,"jpg", file) to save,it’s be broken

the broken result is here

how to fix it problem? thank you

my code:

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import junit.framework.TestCase;

public class ImageResize1  extends TestCase{

    public void testT1() throws IOException{
        URL url=new URL("http://ec.europa.eu/culture/media/programme/images/logos/01_tr_media_col/01_tr_media_col_gif.gif");
        BufferedImage image=ImageIO.read(url);
        File file=new File("C:/temp/java/t7.jpg");
        ImageIO.write(image,"jpg", file);
    }
}

i used:

for(int x = 0; x < scaled.getWidth(); x++) {
    for(int y = 0; y < scaled.getHeight(); y++) {
        int rgb = scaled.getRGB(x, y);
        int alpha = (rgb >> 24) & 0xff;
        if(alpha != 255) {
            scaled.setRGB(x, y,-1); //set white
        }
    }
}

check it from here

it’s not right,result is here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:41:11+00:00Added an answer on May 16, 2026 at 8:41 pm
    AreaAveragingScaleFilter scaleFilter =
        new AreaAveragingScaleFilter(
                    Math.round(originalWidth / factorX),
                    Math.round(originalHeight / factorY));
    ImageProducer producer = new FilteredImageSource(original.getSource(), scaleFilter);
    ImageGenerator generator = new ImageGenerator();
    producer.startProduction(generator);
    BufferedImage scaled = generator.getImage();
    
    for(int x = 0; x < scaled.getWidth(); x++) {
        for(int y = 0; y < scaled.getHeight(); y++) {
            int rgb = scaled.getRGB(x, y);
            int alpha = (rgb >> 24) & 0xff;
            if(alpha != 255) {
                scaled.setRGB(x, y,-1); //set white
            }
        }
    }
    
    
    JPEGImageWriteParam param = new JPEGImageWriteParam(null);
    param.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
    param.setCompressionQuality((float) 0.85);
    java.util.Iterator<ImageWriter> it = ImageIO.getImageWritersBySuffix("jpg");
    ImageWriter writer = it.next();
    dest.getParentFile().mkdirs();
    writer.setOutput(new FileImageOutputStream(dest));
    writer.write(null, new IIOImage(scaled, null, null), param);
    writer.dispose();   
    

    Check it from here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSS like this ul { list-style-image:url(images/bulletArrow.gif); } ul li { background:
When I have an <a> tag set to a specific image background like this:
<td> <img src=http://blog.garethjmsaunders.co.uk/wp-content/feed-icon-16x16.gif/> My feed </td> This is how it looks like: (source: garethjmsaunders.co.uk
I have a GIF image that has an alpha set, and when my site
like this: Groovy: map = ['a':1,'b':2] doubler = this.&doubleMethod map.each(doubler) println map What's the
Code like this often happens: l = [] while foo: # baz l.append(bar) #
Something like this might had worked <%= Html.RouteLink(, new { controller = Article, action
If I have data like this: Key Name 1 Dan 2 Tom 3 Jon
I have something like this: barProgress.BeginAnimation(RangeBase.ValueProperty, new DoubleAnimation( barProgress.Value, dNextProgressValue, new Duration(TimeSpan.FromSeconds(dDuration))); Now, how
Personally I like this one: P.S. Do not hotlink the cartoon without the site's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.