Solved

StretchBlt with GetClientRect.

Posted on 2004-04-13
5
542 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Please show your code.
0
 

Author Comment

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

Thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now