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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:33:31+00:00 2026-05-24T09:33:31+00:00

I want to sharpen a image, my code is given below: public Bitmap RuiHuaBitmap(Bitmap

  • 0

I want to sharpen a image, my code is given below:

 public Bitmap RuiHuaBitmap(Bitmap bitmap) {
    int width, height;
    height = bitmap.getHeight();
    width = bitmap.getWidth();
    int red, green, blue;
    int a1, a2, a3, a4, a5, a6, a7, a8, a9;
    Bitmap bmpBlurred = Bitmap.createBitmap(width, height,bitmap.getConfig());

    Canvas canvas = new Canvas(bmpBlurred);

    canvas.drawBitmap(bitmap, 0, 0, null);
    for (int i = 1; i < width - 1; i++) {
        for (int j = 1; j < height - 1; j++) {

            a1 = bitmap.getPixel(i - 1, j - 1);
            a2 = bitmap.getPixel(i - 1, j);
            a3 = bitmap.getPixel(i - 1, j + 1);
            a4 = bitmap.getPixel(i, j - 1);
            a5 = bitmap.getPixel(i, j);
            a6 = bitmap.getPixel(i, j + 1);
            a7 = bitmap.getPixel(i + 1, j - 1);
            a8 = bitmap.getPixel(i + 1, j);
            a9 = bitmap.getPixel(i + 1, j + 1);

            red = (Color.red(a1) + Color.red(a2) + Color.red(a3) + Color.red(a4) + Color.red(a6) + Color.red(a7) + Color.red(a8) + Color.red(a9)) *(-1)   + Color.red(a5)*9 ;
            green = (Color.green(a1) + Color.green(a2) + Color.green(a3) + Color.green(a4) + Color.green(a6) + Color.green(a7) + Color.green(a8) + Color.green(a9)) *(-1)  + Color.green(a5)*9 ;
            blue = (Color.blue(a1) + Color.blue(a2) + Color.blue(a3) + Color.blue(a4) + Color.blue(a6) + Color.blue(a7) + Color.blue(a8) + Color.blue(a9)) *(-1)   + Color.blue(a5)*9 ;

            bmpBlurred.setPixel(i, j, Color.rgb(red, green, blue));
        }
    }
    return bmpBlurred;
}

but I cannot get the ideal effect. Can someone give more clue, or tell me what is mistake in my code?

Thank you.

  • 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-24T09:33:31+00:00Added an answer on May 24, 2026 at 9:33 am

    You are missing range checking on the rgb values passed to Color.rgb(); you need to normalize rgb values in the [0..255] range before calling Color.rgb() method:

    public static int rgb (int red, int green, int blue) Since: API Level
    1

    Return a color-int from red, green, blue components. The alpha
    component is implicity 255 (fully opaque). These component values
    should be [0..255], but there is no range check performed, so if they
    are out of range, the returned color is undefined
    . Parameters red Red
    component [0..255] of the color green Green component [0..255] of the
    color blue Blue component [0..255] of the color

    Your convolution matrix seems good for a shapen transformation:

     0  0  0  0  0  
     0 -1 -1 -1  0
     0 -1  9 -1  0
     0 -1 -1 -1  0 
     0  0  0  0  0
    

    if you think your effect is too strong, you could also try with:

     0  0  0  0  0  
     0  0 -1  0  0
     0 -1  5 -1  0
     0  0 -1  0  0 
     0  0  0  0  0
    

    as an alternative

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

Sidebar

Related Questions

I want to put a sharpen filter on an image. I have found a
I want to sharpen my skills in terms of gnu/linux and get a better
Want to update specific data in a Table Column. I can use the below
Want to update page after jeditable (using gem on_the_spot) has been updated. Below works
I want to sharpen images in my app. I found this post how to
Want to shuffle a string. This is my code: what is wrong about it?
Want to know what the stackoverflow community feels about the various free and non-free
Want my FireFox at work to be in sync with my FireFox at my
I want to loop over the contents of a text file and do a
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal

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.