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 6881425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:06:21+00:00 2026-05-27T05:06:21+00:00

I derived the Canvas class where in the paint method I draw an Image

  • 0

I derived the Canvas class where in the paint method I draw an Image. When clicking a Command I want to draw in the Canvas a rectangle and a String inside the rectangle , and the Image will still be displayed behind the rectangle, so I want to darken a bit the Image because I want to make a visual effect like the one when showing LWUIT Dialog ( the tint color of the hidden Form ). So how to darken a bit the canvas in this situation ?

  • 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-27T05:06:21+00:00Added an answer on May 27, 2026 at 5:06 am

    Assuming that width and height of image are known, I’d probably first use use Image.getRGB to get ARGB values for image pixels.

    Then, I’d scale the RGB values to make an effect of it becoming darker.

    int[] darken(int[] argb, int percentage) {
        int[] result = new int[argb.length];
        for (int i = 0; i <argb.length; i++) {
            result[i] = darkenArgb(argb[i], percentage);
        }
        return result;
    }
    
    private int darkenArgb(int argb, int percentage) {
        return darkenByte(argb, 3, 100) // keep alpha as-is
                | darkenByte(argb, 2, percentage)
                | darkenByte(argb, 1, percentage)
                | darkenByte(argb, 0, percentage);
    }
    
    private int darkenByte(int argb, int index, int percentage) {
        if (percentage < 0 || percentage > 100) {
            throw new IllegalArgumentException("unexpected percentage: ["
                   + percentage + "]");
        }
        if (index < 0 || index > 3) {
            throw new IllegalArgumentException("unexpected index: [" + index + "]");
        }
        int result = (argb >> index) & 0xFF;
        result = result * percentage / 100;
        return result << index;
    }
    

    From an array obtained with darken method, darkened image could be made using Image.createRGBImage

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

Sidebar

Related Questions

I have created a custom class derived from Canvas, which contain elements which will
I have a class derived from TextBox in C#. I override OnClick method to
I derived a class from CListCtrl called CListCtrlCustomDraw, and use NM_CUSTOMDRAW handler to draw
In my app I have a UIView derived class Canvas that uses touchesBegan: withEvent:
I derived from QLabel class. I want to redefine some events(e.g. mousePressEvent and paintEvent).
I have a View-derived class where I draw a 790x500 (yes, this is odd
When you have a derived class, is there an simpler way to refer to
I have a window (derived from JFrame) and I want to disable the close
I have a class derived from CTreeCtrl . In OnCreate() I replace the default
I have a class derived from Dictionary. I need this class to simulate a

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.