Solved

Fade an image

Posted on 2011-02-28
9
850 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:pivar
  • 4
  • 3
  • 2
9 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34995959
i haven't used it, but i found this
http://stackoverflow.com/questions/4533731/android-fade-effect-between-layouts

please try the same
0
 
LVL 22

Author Comment

by:pivar
ID: 34996038
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
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34996101
why don't you try to put that image inside a layout and then fade that layout instead of that image?
0
 
LVL 22

Author Comment

by:pivar
ID: 34996163
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 40

Accepted Solution

by:
gurvinder372 earned 400 total points
ID: 34996197
0
 
LVL 12

Expert Comment

by:satsumo
ID: 34996340
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
 
LVL 22

Author Comment

by:pivar
ID: 34996389
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
 
LVL 22

Author Comment

by:pivar
ID: 34996450
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
 
LVL 12

Assisted Solution

by:satsumo
satsumo earned 100 total points
ID: 34996624
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now