DrawImage not obeying SetAlpha?
Monkey Forums/Monkey Beginners/DrawImage not obeying SetAlpha?
| ||
Hi all, I am using DrawImage in mojo.graphics to draw an image I have captured from screen (via ReadPixels and WritePixels). It seems that the image is drawn with a certain transparency even though I am using SetAlpha(1.0) right before the DrawImage call. (In other words, I don't want the image to be transparent.) SetAlpha(1.0) DrawImage(myImage, x, y) Is this the way to do it? Confused... ;-) |
| ||
What does your read write code looks like? |
| ||
I copied it from somewhere. Probably from these forums:Function ScreenGrab:Image(x:Int, y:Int, width:Int, height:Int) If x < 0 Or y < 0 Error("ScreenGrab error") If (x + width) > DeviceWidth() Or (y + height) > DeviceHeight() Error("ScreenGrab error") Local screenShot:Image screenShot = CreateImage(width, height) Local pixels:Int[] = New Int[width*height] ReadPixels(pixels, x, y, width, height) screenShot.WritePixels(pixels, 0, 0, width, height) Return screenShot End Function |
| ||
It works fine here: |
| ||
Thanks Jesse! It works here too now. I had a SetColor(50, 50, 50) before the SetAlpha(), Cls() and DrawImage(). Not sure how that made my image look dim. |
| ||
Was it on a black background? 50, 50, 50 is a dark grey colour. |
| ||
@therevills: This code make the image drawn via DrawImage all dimmed in red: SetColor(255, 0, 0) SetAlpha(1.0) DrawImage(screenShot, 0, 0) But if I remove the SetColor call, the image gets drawn in original colors: SetAlpha(1.0) DrawImage(screenShot, 0, 0) I don't see how the SetColor() call has an impact on the image drawn, especially since SetAlpha is set to 1.0. Any ideas? |
| ||
In mojo SetColor() has two functions. One is the expected one of setting the colour if you draw a line or shape etc. The other thing it does is modify the colour of any image you draw by multiplying it by the relative RGB intensity. So before drawing ordinary images you should call Setcolor( 255, 255, 255 ). [I have a SetColorNull() function I call that does that, just to clearly document what's happening.] I personally think they should be separate functions, but this is the way it is done anyway, so you just have to remember it! |
| ||
@Gerry Quinn: Thanks a lot for this reply! Now it makes sense! ☺ I could not find any of this in the documentation, or maybe I have overlooked it. But this is great to know. I was going crazy on this... 😂 |