g.Pixel to RGBSurface.Pixel

Hello,

I am trying to convert from deprecated g.Pixel code to RGBSurface.Pixel code, and it seems to be much longer and more complicated. The below two snippets of code work, and are equivalent. Is there an easier way to convert from a Pixel to a RGBSurface.Pixel?

Thanks :slight_smile:

what picture does “g” belong to?
just use the RGBSurface in place of “g” in this instance

// p = some existing mutable picture
dim rs as RGBSurface = p.rgbsurface
rs.pixel(99,99)=rgb(240,10,10)
// now pixel 99,99 of picture P is red

before you did something like

// p = some existing mutable picture
dim g as grahics = p.graphics
g.pixel(99,99)=rgb(240,10,10)
// now pixel 99,99 of picture P is red

so still much the same

Hi Dave,

This is drawn in the Paint event, and there is/are no pictures.

Yep, the code is a little different.

Thanks for your help, and as you mentioned it is still much the same.

ah… didn’t realize in the paint event… yeah I would not want to instantiate a rgbsurface there

but why not draw a rectangle that is only 1px in size

This is just a demonstration program for a colleague. He wanted to know how to change the colour of 1-pixel, and the older code conveniently did this in one line.

Yep, drawing a rectangle 1 pixel in size would work too.

Thanks Dave :slight_smile:

Or you could create a picture the same size as the graphics object, draw into its RGBSurface, and then draw the picture into the original graphics object.

Yes, that would work also. Thank you :slight_smile: