I have a tiff file while which i'm displaying in a CScrollView using onDraw.

In Ondraw i have the following code:

CClientDC dc(this);
for(unsigned int y=0; y < height; y++)
  for(unsigned int x=0; x < width; x++)
    if( pixel(image,x,y) )

where image is a byte array where bits are pixel on/off switches and the fuction pixel above tests the pixel value for on or off.

however, every time i scroll or repaint the screen this take a time to redraw.

Does anyone know a way to speed this process up.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Why not create a bitmap that contains the image then display the bitmap using BitBlt().  It should be a 100 times faster-literally.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You may want to try

This will stop the draw messages from being sent, until you call:

Invalidate(); //To redraw

Try turning it off when you begin scrolling and back on when scrolling is complete.
Sorry, I was late, and the bitmap idea is better.
As far as I understand you have black &white image tiff file and want to display the image. Than a natural way to speed the process up is to use a memory as a buffer. For instance, you can:

1) Convert your image's pixels to the array in appropriate for the windows bitmap form.

2) Create windows bitmap from the specified array of pixels ( see SetDIBits Win API function )

3) Output the bitmap to the client DC by the usual way.

Sometimes you can extremely simplify the task just manually converting your tiff files to the native windows bmp files. And sometimes giff, tiff, pcx, etc. file loading & displaying is just supported by OLE subsystem.

I'll give you a brief outline of the steps, then you probably should do some reading about the functions uses.  Then ask if you have questions.

You will use CreateCompatibleBitmap() to create a memory based bitmap that is compatible with the screen.

You will need a memory based DC for it that is compatible with the display (and your memory based bitmap.)  You will create this using CreateCompatibleDC() and a handle to the display DC (you can use CreateDC("DISPLAY",NULL,NULL,NULL) to get the display DC handle.)

You need to select the memory bitmap into the memory DC.  IMPORTANT: You need to save the handle to the bitmap returned by this.  You must reselect this handle back into the memory DC before that DC is destroyed!  

You need to intialize the bitmap that you created.  You can do that the way you were using before.  i.e. using SetPixel().  That will work, but is slow.  Howeve, you only have to do it once, so its not too bad.  But a better idea would be to use the SetDIBits() to set the bitmap pixels all at once.

That should get you started.  Do a little research then let me know if you need more.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.