most efficient way to deal with pixel art?

VooDooChicken 40 Reputation points
2023-10-23T15:43:29.02+00:00

to change color for a pixel in the screen you use SetPixel, but that requires lots of validations and if you use it in a screen of 1000 x 1000 that means you run one million redundant or unnecessary validations. Is there a faster way to change the color of a pixel?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,636 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Minxin Yu 11,026 Reputation points Microsoft Vendor
    2023-10-24T02:08:29.63+00:00

    Hi, @VooDooChicken

    Please refer to the similar thread: SetPixel is too slow. Is there a faster way to draw to bitmap

    You can lock the bitmap data and use pointers to manually set the values. It's much faster. Though you'll have to use unsafe code.

    WINAPI Bitmap::LockBits method:
    The Bitmap::LockBits method locks a rectangular portion of this bitmap and provides a temporary buffer that you can use to read or write pixel data in a specified format. Any pixel data that you write to the buffer is copied to the Bitmap object when you call Bitmap::UnlockBits

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Castorix31 83,206 Reputation points
    2023-10-24T05:35:20.2133333+00:00
    0 comments No comments