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

  • SEARCH
  • Home
  • 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 5983829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:17:14+00:00 2026-05-22T22:17:14+00:00

I know the difference in memory usage between byte, unsigned short, and integer, but

  • 0

I know the difference in memory usage between byte, unsigned short, and integer, but when it comes to a BufferedImage, is there a ‘speed’ difference between them?

I have been using the Image type in my code to store images, but I require an alpha layer. Using BufferedImage provides me with ARGB, but my code is /considerably/ slower after making the change from the Image type (and it was only changed for a few objects), so I’m looking for all the performance improvement I can get.

I’m not sure how stupid of a question this may be, so I thank you in response for any replies.

  • 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-22T22:17:14+00:00Added an answer on May 22, 2026 at 10:17 pm

    Tanaki,

    I have found that, when in need of using an alpha channel in a BufferedImage, the best is to premultiply the alpha channel. For example:

    // Create an ARGB image
    BufferedImage bi = new BufferedImage(512, 512, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bi.createGraphics();
    // Fill the background (for illustration)
    g.setColor(Color.black);
    g.fill(new Rectangle(0, 0, 512, 512));
    
    AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
    // Keep the original composite
    Composite original = g.getComposite();
    g.setComposite(alpha);
    
    // Paint with transparency
    Rectangle r = new Rectangle(100, 200, 50, 50);
    g.setColor(Color.magenta);
    g.fillRect(r);
    g.setComposite(original);
    // ... paint further shapes or images as necessary
    // ...
    g.dispose();
    
    // Convert to a premultiplied alpha image for fast painting to a Canvas
    BufferedImage biPre = new BufferedImage(512, 512, BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics2D gPre = biPre.createGraphics();
    gPre.drawImage(bi, 0, 0, null);
    gPre.dispose();
    
    // clean up:
    bi.flush();
    
    
    // Now use biPre for painting to a Canvas, or a Component.
    // ...
    
    // Remember to flush it when done!
    biPre.flush();
    

    The reason for painting first to a TYPE_INT_ARGB is to ensure that all alpha gets painted as you expected (not pre-multiplied every time!). Then, when done, paint the whole image onto a TYPE_INT_ARGB_PRE, which is then able to bring the data to the screen with good speed.

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

Sidebar

Related Questions

I would like to know difference between static variables and global variables in terms
I know the difference between ASP.NET webforms and ASP.NET MVC and I've seen quite
I know the difference between manage and unmanaged DirectX. My question is if I
I want to know the difference Between System.ApplicationException and System.Exception . Can anyone explain
I want to know the difference between : $this->forward(module, action); And $this->redirect(module/action); My first
Please let me know the difference between ~ and ! operator in java.
I am eager to know the difference between a const variable and a static
Now, I know a difference between parameters in a URL and a POST parameter:
Is there a difference in the order of uniq and sort when calling them
I want to know difference between recursive function and using a stack in terms

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.