Solved

StretchBlt with GetClientRect.

Posted on 2004-04-13
5
555 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 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

724 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