Solved

StretchBlt with GetClientRect.

Posted on 2004-04-13
5
552 Views
Last Modified: 2013-11-20
Hi,
   I have an image viewer that does zooming and scroll. this image viewer is built with the document view architecture.

Currently, my program does this,      

pDC->StretchBlt(0, 0, srcX * zoomfactor, srcY * zoomfactor, &bmDC, 0, 0, srcX, srcY, SRCCOPY);

This is very inefficient when the zoomfactor is very huge, say 10. I tried to use GetClientRect to restrict the destination DC's area when doing StretchBlt but it does not scroll properly after that.

Anybody knows what is the problem? Or can show me the proper way to do this?

Thanks.
0
Comment
Question by:pcssecure
  • 3
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 10812177
Use GetScrollPosition to get current scroll position in the view. Having this point, you can draw only appropriate rectangle which should be shown on the screen.

Something like this:

pDC->StretchBlt(
    0,
    0,
    srcX * zoomfactor,
    srcY * zoomfactor,
    &bmDC,
    0,
    0,
    srcX,
    srcY,
    SRCCOPY);

replace with (pseudo-code):

pDC->StretchBlt(
    <current X scroll position>,
    <current Y scroll position>,
    <client width>,
    <client height>,
    &bmDC,
    <left of source rectangle which should be drawn>,
    <top of source rectangle which should be drawn>,
    srcX/zoomCoefficient,
    srcY/zoomCoefficient,
    SRCCOPY);

You need some beginner math stuff to accomplish this. The idea is to draw minimum, taking into account current scroll position.

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10812194
Another way is creating of memory DC with full size (bitmap size * zoom coefficient) and keep image in it. In OnDraw function use BitBlt instead of StretchBlt.
0
 

Author Comment

by:pcssecure
ID: 10812733
I tried the first method before i posted this question but it didn't seem to work.
BTW, my CView is actually CScrollView. It handles the scrolling and refreshing automatically. Will this have any adverse effect?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10812750
Please show your code.
0
 

Author Comment

by:pcssecure
ID: 10812965
Problem solved thanks very much. There was something wrong with my beginner math...

Thanks.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question