Link to home
Start Free TrialLog in
Avatar of fraughtneo
fraughtneo

asked on

Urgent...Regarding Zooming Bitmaps

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.

Avatar of manojbkumar
manojbkumar

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
Avatar of fraughtneo

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of manojbkumar
manojbkumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.