Fade an image

Hi,

I have an image that I would like to "fade" to white. Maybe fade is not the correct term here. What I would like to do is animate a change of the colors to all white, that is, lessen the color. (Maybe this is not the correct term either. As you can see, I'm not a graphics guy.)
This would be in Android/Java.

Is this possible in code?

/peter
LVL 22
pivarAsked:
Who is Participating?
 
Gurvinder Pal SinghCommented:
i haven't used it, but i found this
http://stackoverflow.com/questions/4533731/android-fade-effect-between-layouts

please try the same
0
 
pivarAuthor Commented:
I would like to apply this on an image, drawing it to the canvas myself. How would this be implemented with your solution?

thx
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Gurvinder Pal SinghCommented:
why don't you try to put that image inside a layout and then fade that layout instead of that image?
0
 
pivarAuthor Commented:
Because I want to implement this in a drawing engine which draws various types of imageobject to the same canvas, where the fader object would be one. Because of this I would like to be able to transform the image/Bitmap.
0
 
satsumoSoftware DeveloperCommented:
Assuming Android Canvas matches HTML5 Canvas, and you have a 2D context, then its code like this.

context.fillStyle = "white"
context.fillRect (top, left, width, height)
context.globalAlpha = ? // some amount of transparency, 1 = full opaque, 0 = full transparent
context.drawImage (image, top, left, width, height)

Open in new window

The program would change the globalAlpha value from one to zero over a time period.
0
 
pivarAuthor Commented:
satsumo, would that affect the whole canvas, or just my image that I'm drawing? What is meant by "Android Canvas matches HTML5 Canvas"?
0
 
pivarAuthor Commented:
Just to confirm that we're on the right track. It is the transparency one should change to get the impression of an image "loosing" its colors?
0
 
satsumoConnect With a Mentor Software DeveloperCommented:
The globalAlpha setting is a state, it affects whatever you draw after setting it.  I intended there to be another line at the end of that code, so that the transparency dosen't affect anything drawn afterwards.

context.globalAlpha = 1

Open in new window

The Canvas is an invention of Apple, its in the latest HTML specification and its supported by most web browsers (on any OS).  I haven't programmed for Android, I've assumed that a Canvas on Android has the same interface and behaviour as Canvas in a browser.  I could be completely wrong, though Goggle likes open standards and the Chrome browser has very good Canvas support so it would make sense.

There are many ways to make an image lose it's colours, transparency is the simplest and most widely supported.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.