WritePixels, empty image.
Monkey Targets Forums/Flash/WritePixels, empty image.
| ||
I'm trying new WritePixel method but I can't write pixels to image. I get empty image on debug and release, also if I change fog.WritePixels(fogtab , 0,0,sx,sy , 0,0) to fog.WritePixels(fogtab , 4,4,sx,sy , 0,0) I get 4 pixel white border, and no "out of array" error. Any ideas? fog = CreateImage(sx,sy) Local fogtab%[sx*sy] For Local x% = 0 To sx-1 For Local y% = 0 To sy-1 fogtab[x*sy+y] = ToARGB(256,256,256,256) ' returns 65536 so it's binary 111....., should be full white. Next Next fog.WritePixels(fogtab , 0,0,sx,sy , 0,0) End Method Method ToARGB%(r%,g%,b%,a%) Local argb% argb = a Shl 8 argb = r Shl 8 argb = g Shl 8 argb = b Shl 8 Return argb End Method |
| ||
Nvm, I found the bug. |
| ||
So what was the bug? |
| ||
obviously 'ToARGB(256,256,256,256)', while the maximum is 255 per channel and also 'ToARGB' itself, cause it uses only the green channel.. |
| ||
I know this is an old thread, but for anyone struggling with this, as I was, here's a corrected version that works: local color_red:Int = 255 local color_green:Int = 0 local color_blue:Int = 0 local alpha:Int = 255 fog = CreateImage(image_width, image_height) Local fogtab%[image_width * image_height] For Local x% = 0 To image_width-1 For Local y% = 0 To image_height-1 fogtab[x * image_height + y] = ToARGB(alpha, color_red, color_green, color_blue) 'This will be red Next Next fog.WritePixels(fogtab , 0, 0,image_width,image_height , 0,0) 'This works to generate the right colors Method ToARGB%(r%,g%,b%,a%) Local argb% argb = a | b Shl 8 | g Shl 16 | r Shl 24 Return argb End Method Obviously you also need to render the image in OnRender for example: DrawImage(fog, 0, 0) |