?
Solved

StretchBlt with GetClientRect.

Posted on 2004-04-13
5
Medium Priority
?
557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

752 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