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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:35:11+00:00 2026-06-06T01:35:11+00:00

Is there a way to do image color filtering in Google Web Toolkit? Something

  • 0

Is there a way to do image color filtering in Google Web Toolkit? Something like Color Matrix Filter using Action Script 3. Here is action script example:
AS3:How to change a colored Bitmap's BitmapData to black and white?

  • 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-06-06T01:35:12+00:00Added an answer on June 6, 2026 at 1:35 am

    For image manipulation in HTML (and therefore GWT) you need to use the canvas element. To my knowledge canvas doesn’t give you any shortcuts for applying filters, you will need to get in and modify the pixels by hand. Let’s use black-and-white as an example. You need to be sure that the image has already loaded before you can call this method:

    public void toBlackAndWhite(Image image)
    {
        // Create an off-screen canvas element to do the work.
        Canvas canvas = Canvas.createIfSupported();
    
        // Do nothing if canvas is not supported.
        if (canvas == null)
            return;
    
        // Size the canvas to fit the image.
        canvas.setCoordinateSpaceHeight(image.getHeight());
        canvas.setCoordinateSpaceWidth(image.getWidth());
    
        // Pull the image's underlying DOM element
        ImageElement img = ImageElement.as(image.getElement());
    
        // The 2D context does all the drawing work on the canvas
        Context2d context = canvas.getContext2d();
    
        context.drawImage(img, 0, 0); // Now the canvas contains the image.
    
        // ImageData represents the canvas rgba data as an array of bytes.
        ImageData imageData = context.getImageData(0, 0,
                                  image.getWidth(), image.getHeight());
    
        // Now the real work:
        for (int x = 0; x < imageData.getWidth(); ++x) {
            for (int y = 0; y < imageData.getHeight(); ++y) {
                 // RGB values are 0-255
                 int average = (imageData.getRedAt(x,y) +
                                imageData.getGreenAt(x,y) +
                                imageData.getBlueAt(x,y)) / 3;
    
                 imageData.setRedAt(average, x,y);
                 imageData.setGreenAt(average, x,y);
                 imageData.setBlueAt(average, x,y);
             }
        }
    
        // ImageData is a copy of the data on the canvas, so
        // we need to write it back.
        context.putImageData(imageData,0,0);
    
        // Now the canvas contains a black and white version
        // of the image. Canvas is a Widget so you could attach
        // it to the page directly if you want. Here we're going
        // to replace the contents of the original image element
        // with a url-encoded version of the canvas contents.
        image.setUrl(canvas.toDataUrl());
    }
    

    Not quite as elegant as actionscript but it will do the job. As you can imagine this will chew up a good deal of processor time on larger images, if you need better performance you might consider gwtgl.

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

Sidebar

Related Questions

Is there any way to cut an image into smaller pieces using JavaScript? Like,
Is there a way I can detect an image URL, like: http://mysite.com/image.jpg but with
Is there any way to change the background color/image of the details UITableView in
Is there a way to create a background using CSS without the image? with
Is there a way to specify an alternative background image/color for a Button in
Is there a way to change colors of an image much like in Flash/ActionScript
I was wondering if there is a way to change an image color scale
Is there any way to highlight tab icon image programmatically without using separate drawable
I there a way to getting picture(image) from URL without downloading? I use the
Is there a way to fake a foreground-image analagous to a background-image in CSS?

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.