Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
theSmaw
Level 7

Controlling bitmap opacity

I believe this may already have been asked and not been answered: viewtopic.php?f=34&t=50839&p=344901&hilit=alpha#p344901

I have a requirement to fade images (roBitmap) in and out on the screen. Is this possible?


Thanks
0 Kudos
10 Replies
destruk
Level 10

Re: Controlling bitmap opacity

http://sdkdocs.roku.com/plugins/viewsou ... Id=3114035

Looks like by redrawing the destination surface you should be able to change the alpha values for combining new data drawn to it.
0 Kudos
Highlighted
TheEndless
Level 7

Re: Controlling bitmap opacity

If you're just wanting to fade in and out and not do a cross fade, and the background color is solid, you could fake it by drawing a rect over the bitmap with increasing/decreasing alpha values.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Roku Employee
Roku Employee

Re: Controlling bitmap opacity

This hasn't been added to the online docs yet:

DrawObject, DrawScaledObject, & DrawRotatedObject take an optional RGBA color parameter. To modulate the alpha, pass in &hFFFFFFAA where AA is the hexadecimal alpha value.

Example: DrawScaledObject(x as Integer, y as Integer, scaleX as Float, scaleY as Float, src as Object, rgba as integer)

(this allows you do do a crossfade of solid images).

This does not work on 3.1 firmware devices and will cause your code to crash.



- Joel
0 Kudos
theSmaw
Level 7

Re: Controlling bitmap opacity

Brilliant Joel, that's exactly what I'm looking for. Thanks!
0 Kudos
Arthy74
Level 7

Re: Controlling bitmap opacity

Hello,

I am sorry but apparently i have an error when using this last "mask" parameter with DrawScaledObject
(works for DrawObject method)

m.canvas.DrawScaledObject(xOffset, yOffset, m.scaleX, m.scaleY, m.bitmapData, &hFFFFFFFF)


Show this error:
Type Mismatch. (runtime error &h18)

Tested on Roku 3 and Roku 2 XS (both updated)
0 Kudos
Roku Employee
Roku Employee

Re: Controlling bitmap opacity

Could you be using a legacy Roku device running 3.1 firmware? Those don't support the extra parameter.

- Joel
0 Kudos
squirreltown
Level 9

Re: Controlling bitmap opacity

"RokuJoel" wrote:
Could you be using a legacy Roku device running 3.1 firmware? Those don't support the extra parameter.

- Joel

Pretty sure there are no Roku3's running 3.1

I use this feature to death but because of it's un-documented-ness I only know about it because Joel has posted it before. I've never made it work on drawRotatedobject and i know i've tried. Works like a charm on drawObject & drawscaledobject though.
Kinetics Screensavers
0 Kudos
TheEndless
Level 7

Re: Controlling bitmap opacity

"Arthy74" wrote:
Show this error:
Type Mismatch. (runtime error &h18)

The "Type Mismatch" would suggest that one of your variables isn't equal to what you think it is. Is it possible you don't have a valid bitmap in m.bitmapData? Can you verify, without changing anything else in the code, that it works if you remove the last parameter?
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
mbhakak
Level 7

Re: Controlling bitmap opacity

I tested the code you have with my own bitmap, and indeed, I get the type mismatch error when I apply a rgba value on the DrawScaledObject call.
I verified that the image is fine, so when I remove the rgba parameter, the image does show up.

I am running Roku 3 on a 6.1 build

I did some more digging and found that the method DrawObject also has a RGBA parameter that is undocumented.
That method worked.

SO: someScreen.DrawObject(20, 20, image, &hFFFFFF33) did show the image with an alpha, no error. Hope that helps....
However, I can imagine someone wanting to draw a scaled image scaled with transparency....hmmm, something to worry about later?
0 Kudos