Did I see a posting on LinkedIn? Optimizing RGBSurface

I was optimizing a piece of code that relies heavily on

picture.RGBSurface.Pixel(c, r) = RGB(pixr, pixg, pixb)

I think i saw a posting on linked in on how to optimize this with tutorial etc.

For starters, save a reference to the picture’s RGBSurface for reuse, instead of generating it new each time:

Var theSurface as RGBSurface

theSurface = myPicture.RGBSurface

theSurface.Pixel(c, r) = RGB(pixR, pixG, pixB)

That should make a big difference if you are making a lot of changes.

2 Likes

Also, use the Y value as the outer loop and the X value in the inner loop, if you are looping through all the pixels.

2 Likes