• Advertisement

Archived

This topic is now archived and is closed to further replies.

SetPixel is too slow!!!

This topic is 4972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In Win32 programming is there a faster way to change i specific pixel of a DC than SetPixel? Thx ----------------------------------------------- Here comes the Thnikkaman!

Share this post


Link to post
Share on other sites
Advertisement
How fast do you need to be able to change that pixel? The only way it would be too slow is if you are going to change a lot of pixels. If you want to make larger changes to an image, then work out a double buffering scheme for your program: Draw to an array and then use SetDIBitstoDevice.

Share this post


Link to post
Share on other sites
The DIBBits version, in plain VB. Remember to declare the API function calls and the BITMAP definition (use the API Text Viewer tool).


Public Function GetBitmapArray(ByVal bDC As Long, bBytes() As Byte) As BITMAP
Dim tBitmap As BITMAP, nWd1 As Long, nHt1 As Long

Call GetObjectAPI(bDC, Len(tBitmap), tBitmap)
nWd1 = tBitmap.bmWidthBytes
nHt1 = tBitmap.bmHeight
ReDim bBytes(0 To nWd1 - 1, 0 To nHt1 - 1)
Call GetBitmapBits(bDC, nWd1 * nHt1, bBytes(0, 0))

GetBitmapArray = tBitmap
End Function

Public Sub SetBitmapArray(ByVal bDC As Long, bBytes() As Byte, tBitmap As BITMAP)
Call SetBitmapBits(bDC, tBitmap.bmWidthBytes * tBitmap.bmHeight, bBytes(0, 0))
End Sub


For C/++... you need to allocate the memory and keep a BITMAP structure handy. The BITMAP structure only describes the drawing surface, it doesn''t hold the pixel data. Call GetBitmapBits only once to initialize the array and fill the BITMAP structure. Then call SetBitmapBits and send a message to (I think) the default WM_PAINT handler to redraw (Not sure on that bit, it''s been a while).


HRESULT GetBitmapBits( HDC hdc, BITMAP * bm, BYTE * pixmap ) {
GetObjectAPI( hdc, sizeof(BITMAP), bm);
return GetBitmapBits( hdc, bm.bmWidthBytes * bm.bmHeight, pixmap );
};

HRESULT SetBitmapBits( HDC hdc, BITMAP * bm, BYTE * pixmap ) {
return SetBitmapBits( hdc, bm.bmWidthBytes * bm.bmHeight, pixmap ); };

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Or you could just use DirectDraw or something instead of GDI, which just plain isn''t fast enough to write games in.

Share this post


Link to post
Share on other sites
There is no good way of drawing pixels in GDI. Windows was not designed with game making in mind. If you want to get decent frame rates you''ll need a API such as DirectX or SDL(see my signature).

--------------------------------------------------------------------------------
[C++ Reference | Java API | SDL Home Page | Lua Scripting Language | Python Scripting Language |
Chris Taylor''s Design Document (Downloadabe MS-Word Only) | Blitz Basic Homepage ]

Share this post


Link to post
Share on other sites

  • Advertisement