Urgent...Regarding Zooming Bitmaps

fraughtneo
fraughtneo used Ask the Experts™
on
Hello experts,

I have a problem. I am writing an application which uses 8-bit grey scale images of size say 10000 x 10000. I want to display the image on the screen and when I display it using 1:1 (no Zoom) using API Function StretchDIBits(....) or say any DrawDIBDraw(....), it works fine.

But I want to zoom the image say upto 25% - 250%. The problem is that when i scroll the image, especially when it is zoomed even to say 125%, the performance is detoriated. (I see that scrolling is not as smooth as it used to be with 100%).

I use a scrollview-derived view class to display the image and use memory alloc (GlobalAlloc) for storing the bitmap. I recalculate the size of the view  on its OnDraw according the the Zoomfactor. I hope this information will do.

Thanx in advance,
Neo.

PS.: If anyone has the idea for doing this, please include the code if possible.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most probably the problem is because of the time taken by StretchDIBits for calculation. Instead you can create a Zoomed bitmap in your OnZoom function with the new height width parameters and use BitBlt to display it in ondraw(). You can use the bitmap zooming algorithm in the following link:
http://www.codeguru.com/bitmap/SmoothBitmapResizing.html
You can optimize it to take the pixel data as input.
Another way is using DC functions for creating the scaled image.
1. Create a temporary DC(DC1).
2. Create a bitmap of new dimension and select it on to DC1.
3. Create a temporary DC(DC2).
4. Select source bitmap on to DC2
5. Use DC1.stretchBlt()

Hope this helps
Manoj

Author

Commented:
Hi Manoj,
The code provided by the link u gave me just provides an image of higher quality than what is provided by the StretchDIBits or StretchBlt functions but what I need is speed and not quality.

Regarding the second way, I use a very large bitmap of order might be 10000 X 100000 and is it a good way to create another DC and a new bitmap in this scenario?

Thanx for ur help anyways.

If you know a way out to solve my problem, I would be thankful to you.

Have a nice time :-)

Neo.
Hi Neo
I am not proposed the link as a high quality scaling solution. You are using StretchDIBits to scale your image in OnDraw() function. But this function is called each time the window needs to be painted and the StretchDIBits has to perform its calculations for scaling each time. This is takes the CPU. I suggested creating a zoomed bitmap (or buffer) in the OnZoom() function and call BitBlt or StretchDIBits so that it does have to perform the zooming operation in OnDraw().The link contains an image scaling algorithm. If it’s not acceptable to you, I am sorry. I don’t know any alternatives to suggest.
Manoj
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Author

Commented:
Hi Manoj,
Thanx for ur reply.
Finally I solved the problem in the following way.
Instead of Stretching the whole image, I stretched the part of the image that is visible to me and on scrolling, I calculated the new coordinates which would get me a new image...Doing this way made my application run faster than ever but there is a new problem now which is the flickering.
I donot know how to reduce the flickering or implement a smooth approach to scrolling problem.

If you have any idea, please help me out.

It was your idea which made me think abt the CPU time consumed by the StretchDIBits. Thanx for your help once again.

I would like to know if you have any answer for flickering problem. If you have it please let me know.
Thanx in advance and have a nice time.....

Deepak.
Hi Deepak
Override WM_ERASEBKGND message. In the OnEraseBkGnd function put return TRUE instead of calling default. Now it is your responsibility to draw the background. (I think u are doing it in OnDraw)

Manoj

Author

Commented:
Thanx Manoj for ur help without which the project wud have been a great success...
I have submitted the project and my boss is delighted with it.

Thank you once again...

Deepak.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial