Pixel-by-Pixel drawing

Is there any fast and efficient way to draw pixel by pixel images ??
I need to make a program which extracts some image data from a binary file and draw them on a window. The image data format is several bits per pixel, so I'm thinking on grouping bits and draw pixel by pixel according to its meaning.

The faster way to achieve this is to use TBitmap.ScanLine();
You pass the row as parameter and you have a pointer to the row, so each X bits you have a new pixel of the row, where X is the image color depth (16 bits, 24 bits, etc...).
Setting TBitmap.PixelFormat = pf24bits; will help a lot since red for the pixel will be 1 byte, blue and red to.

hello patroclus02 , , you ask - -
Is there any fast and efficient way to draw pixel by pixel images ??

I guess that would depend on what you are drawing on, if you are drawing on a windows Control DC (canvas in Delphi) then the answer may be NO, as with a window DC, I would think that the SetPixel( ) function would have to be used, a SLOW method if you need to change alot of pixels. . . but with a system Bitmap you can get the pixel definition memory and change it, that is usually called a ScanLine operation, which is Very Much faster than the DC SetPixel( ) function . . .

you do not really say what kind of image data you get your pixel data from, using a scanline operation is faster but can get complicated, with input pixel data that does not match the scanline pixel data. . . . ., do not know what you mean by -
"thinking on grouping bits and draw pixel by pixel according to its meaning"

maybe more info about what kind of image data you have to get would help?

Everything is relative. You can draw a boatload of pixels in one second on a modern PC. Problem is, images require boatloads of pixels. However, it may be "good enough" for your purposes.

Using nothing fancy at all in terms of hardware (2 GHz Celeron, and whatever video card came with the Dell) , I just ran the code below (using a timer interval of 5000 msec and a form defined ClientWidth & ClientHeight of 500 each).

With full form displayed on screen (without clipping) its takes me about 1.9 seconds to draw a million pixels. With another form overlaying the entire client region of the form, it takes about 0.8 second to draw a million pixels. Replacing the call to Pixel with a simple noop drops to the to under 0.01 seconds. Interestingly, I if replace the pixel call with sleep(0), I get the same execution times.

Since modern video cards are 24/32 bits, you probably won't be able to optimize based on bits per pixel (without putting user into a low-color graphics mode)

What I want to do is extract tile images from a binary file. Tile images are small images (8x8 pixels) which you use to make bigger images. I need to display a tile image set, and then, several objects made from different tiles.

"thinking on grouping bits and draw pixel by pixel according to its meaning"
This means that I take 2 bits at a time (image information is 2 bits color depth. Later on, you can add other 2 bits to get up to 16 diferent colours, but inside the binary file, only 2 bits are stored). So each 2 bits, I draw a pixel depending on if they are 00, 01, 10 or 11.
So far I'm using a DirectX libraries for drawing routines, and a method called "Point", which just takes a sparameters X, Y and colour of pixel to draw. So far, it works fine it seems... Usually I don't need to draw more than 300.000-400.000 pixels at a time.

you really should have mentioned that you are using DirectX methods, that makes an extream difference in the code methods. . .

I do NOT know the relative performance values for the "Point" method, since ALL performance values are relative (compare the speed of one method to another method), you would need anouther method to compare it to to make a faster or slower judgement. . . .

if the "Point" method is working for you (you do not have some timing errors, or fram rate drop), you may want to continue to use it. . .
if it is not working for you, you may look at another method (I have not used any directX in a number of years) for faster results, , I can remember a function that would draw a bitmap to the directX DC, perhaps a you can get the 8x8 pixel 2 bit info and place it on a 8x8 bitmap (of the needed color depth) with a scanline and then draw the 8x8 bitmap on the DirectX output DC. . .
as I said, I do not have the knowledge to give much for DirectX,

if you do not get any helpful comments here, you may want to ask this question AGAIN, and be sure to specificly ask about DirectX methods

?????
As I have tried to say before, IF you want to use a bitmap then the ScanLine method is fast compared to SetPixel( ) or Canvas.Pixel(x,y), but I DO NOT KNOW any performace values for the "point" method, so I can not compare,

if you like I can do a 8x8 pixel TBitmap scanLine using 4 colors input (as in a 2 bit color depth you describe) and then you will need a method to "Paint" this bitmap onto whatever you are drawing on. . .
you may can test the relative performance of the two methods?

The uses clause is one of those things that just tends to grow and grow.
Most of the time this is in the main form, as it's from this form that all others are called.
If you have a big application (including many forms),
the uses clause in the in…

Have you ever had your Delphi form/application just hanging while waiting for data to load?
This is the article to read if you want to learn some things about adding threads for data loading in the background.
First, I'll setup a general applica…

Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video.
If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…