Solved

StretchBlt with GetClientRect.

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 216
unable to delete all specified values regedit 38 865
Window placement 17 99
JQuery serialize and unserialize 8 260
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 …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 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