Pixmaps and Images

Started by JBR, November 27, 2023, 02:07:06

Previous topic - Next topic


I was getting on fine using pixmaps the correct colours are plotted.

However when I copy the pixmap to the Images pixmap the red & blue are swapped when I draw the image.

I know you can change the format of a 'bare' pixmap - is there anyway to do so with an Image.

Ty Jim.


Images will be created by loading Pixmaps with LoadImage(), not by copying. This way the colors should stay correct.

If you want to change something inside images, you should convert them to a Pixmap with LockImage() and afterwards unlock them with UnlockImage()

...back from Egypt


You could convert the pixmap (color) format ... 

If you really have an existing "TImage" (with its own pixmap) and plan to copy pixels from a pixmap into it (with pix = LockImage(img) ... pix.writepixel(). ..) then you need to ensure that both pixels (integer values) are from the same "format".

If they are of a different format, you need to convert them - eg by splitting the "incoming" pixel color into R, G, B, A (according to THEIR pixmaps color format) and then merge them back into the "target" color format.

If you used "pixmap.paste" then this will already convert it for you.

If you want to copy a portion of "source" into "target" you can use pixmaps's "window()" function

targetPix.Paste( sourcePix.Window(10,10,20,40), 0,0)
-> paste a sub-area (10,10 to 30,40) into targetPix - with the offset 0,0 (so right at the top left)



Thanks guys,


Tried both methods, about the same speed.

drawpixmap takes about 2ms and drawimage takes about 5ms. (altering the pixmap in each).

Shame it has to waste time copying from RAM to Graphics RAM every time the pixmap is changed every frame.

Best, Jim.


Depending on what you change in the pixmap you might consider TRenderImage (render 2 texture).
Which can be useful for rendering out eg "gui widgets" into a texture and then drawing it. All on gpu then.