Re: Scaling of data into dc



See below...
On Sun, 13 May 2007 12:18:03 +0200, Matthias Pospiech <matthiaspospiech@xxxxxxxx> wrote:

Joseph M. Newcomer schrieb:
This is a completely wrong approach. Use SetViewportExt/SetWindowExt to accomplish this.
Otherwise, you end up scaling the bitmap which gets really lousy representation for the
graphics.

I tried to implement the scaling with SetViewportExt/SetWindowExt.

That however worked only partly

- What is the difference between the two ?
****
One sets the specificaiton of the size of the viwport and one sets the specification of
the size the window. The ratio of the two provides the mapping between physical and
logical coordinates. RTM.
****
- I changed in CMemDC.h the lines

SetMapMode(pDC->GetMapMode());
SetWindowExt(pDC->GetWindowExt());
SetViewportExt(pDC->GetViewportExt());

to

SetMapMode(MM_ANISOTROPIC);
SetWindowExt(CSize(m_rect_dest.Width(), m_rect_dest.Height()));
SetViewportExt(CSize(m_rect_source.Width(), m_rect_source.Height()));
*****
You have not specified what pDC is. Note that you would apply the mapping mode to EITHER
the MemDC or the actual DC, but not both, because then the two mapping modes compound each
other. If you feel the compulsion to use the intermediate memory DC, then you would apply
it there, although it appeared that the only reason you were doing this is so you could do
a StretchBlt, so unless there are other reasons, the need for the MemDC has evaporated.

You could also have used MM_ISOTROPIC unless you plan to allow aspect ratio distortions.
****


and changed from StrechBlt to BitBlt again, because I do not want to mix
two differend streching ways.
****
Yes, that's right. It is not clear you even need the extra MemDC and the BitBlt, unless
you have other reasons for doing this
*****

The generated bitmap is now scaled, BUT

- only the size of the data (if smaller the the dc size) is
invalidated/shown, although the UpdatePlot invalidates the whole area:
*****
This is probably caused by the apparent rescaling of the original DC. Scale only one.
*****

which means that if the data has size 50x50 and the dc 100x100 then the
data is streched on the dc twice, but only the area 50x50 is shown.

void CGraphCtrl::UpdatePlot()
{
CRect rc;
GetClientRect(rc);
InvalidateRect(&rc);
*****
Remove the three above lines. Replace with
Invalidate();
****
UpdateWindow();
}

Now my code has changed but the overall problem is still the same and I
have no idea how to proceed.
*****
Scale only the one you are drawing into. The MemDC needs to have the same dimensions as
the target window.
joe
*****

Matthias
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Scaling of data into dc
    ... you end up scaling the bitmap which gets really lousy representation for the ... Well, I understand the sizing of the viewport, but sizing of the window ... I do apply these commands to the dc of MemDC (so it is inside the MemDC ... Scaling will then be automatic. ...
    (microsoft.public.vc.mfc)
  • Re: From memDC to a Bitmap..... How?
    ... I am having a memDC in which I have drawn somethig, ... to have a CBitmap object created from the memDC. ... This creates a CBitmap bmp, which has not yet been drawn, which is compatible with CDC cdc. ... You have a pointer to a DC whence you want to extract a bitmap, and you know the size of the bitmap ...
    (microsoft.public.vc.mfc)
  • Re: From memDC to a Bitmap..... How?
    ... Once you have your CDC you can use CPen's and CBrush'es for lines and shading, you can blit a bitmap from another CDC, and so on. ... It all adds up - just like real drawing. ... In the first instance a CDC is associated with the surface of a device but the memDC we discussed is a sort of virtual piece of paper in memory, which you can use to extract an image in the form of a CBitmap, which you can carry around and reuse later. ... In some cases I want a printer-resolution image of a printed page, and in that case I deliberately use a monochrome bitmap in the manner described by Norbert. ...
    (microsoft.public.vc.mfc)
  • Re: StrechBlt
    ... Da Du schon eine Bitmap hast macht es keinen Sinn noch mal einen MemDC ... Dann würde nur noch ein sehr schneller BitBlt ... nicht macht und TRUE returniert. ...
    (microsoft.public.de.vc)