how to do Get Pixel Alpha?

Monkey Forums/Monkey Programming/how to do Get Pixel Alpha?

Raul(Posted 2013) [#1]
I searched the forum and found some interesting topics like this one:
http://www.monkeycoder.co.nz/Community/posts.php?topic=1853

but I was not able to implement it.

I am interested in getting the pixel alpha of my game object which is if course a PNG.

In BlitzMax I am creating an array of alphas when loading the game graphics and during the gameplay at mouse click I just calculate the 'image click' from the world mouse click and compare the alpha from my array :D

Anyway, I think will be enough to make a 'mask' at the load of the level but this beats me... any ideas?


therevills(Posted 2013) [#2]
Have a look at this code:
http://www.monkeycoder.co.nz/Community/posts.php?topic=3488

It uses the in built pixel commands so you don't need to extern native ones.


Perturbatio(Posted 2013) [#3]
Not sure how performance friendly it would be but if you setcolor to 0,0,0 then draw the graphic on a white background you'd have a blank and white image you could read the pixel data from. (white being fully alpha)


Raul(Posted 2013) [#4]
I receive an "Invalid array rectangle" when I try to CreateImages.. have no idea why :|
EDIT: ok, solved this part.

@therevills: I tried something similar earlier (to create some kind of alpha mask almost like your code), but the loading time was huge.. I have 50-60 objects per scene with dimmensions from 30x30 up to 150x100

I need these to test when the player is clicking on an object for a Hidden Object game.. Is there a good way to make this?


Perturbatio(Posted 2013) [#5]
Another thought would be to make the image double height, have the lower half contain the click mask and use drawimagerect to draw just the upper half on screen.

You could apply an offset of half the image height to test the colour on the lower half.


Raul(Posted 2013) [#6]
guys, it is working and it is fast as hell.

I am using therevills method and it is just fine. thank you ;)