CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Oct 2004
    Posts
    481

    How to create DC with specific resolution?

    Hi GURUs,

    Do you know how to create DC with specific resolution? Normally, I created DC by calling CDC::CreateCompatibleDC(NULL);. This will create the DC with the screen resolution (96dpi). If you call CDC::GetDeviceCaps(LOGPIXELSX);, you will see that the return value is 96.

    So, I am just wondering, how to create a DC with specific resolution such as 200x200 or 120x103, etc...? If this is not possible, how to set the temporary resolution of the DC at runtime?

    Thanks for any help in advance...

    Cheers

  2. #2
    Join Date
    Oct 2004
    Posts
    481

    Re: How to create DC with specific resolution?

    Can anyone help me, please? GURU???

  3. #3
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: How to create DC with specific resolution?

    the dpi is dependent on h/w , right ?

  4. #4
    Join Date
    Oct 2004
    Posts
    481

    Re: How to create DC with specific resolution?

    Hi Kirants,

    I think so.

    I think the resolution in DC depends on the hardware. Therefore, I am just wondering if I could create "a temporary DC" with specific resolution.

    Any idea?

    Thanks...

  5. #5
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: How to create DC with specific resolution?

    A resolution only applies to a physical entity , right ? A memory DC doesn't have that. A memory DC is simply a canvas and doesn't have to draw at 96dpi on the screen.

    So, I am confused..

    Are you sure you are concerned about resolution and not something else ? You aren't talking about the viewport coordinates, are you.. Something like , you want the DC to have a coordinate system of 100 by 100 and all drawing operations would scale accordingly ??

  6. #6
    Join Date
    Oct 2004
    Posts
    481

    Re: How to create DC with specific resolution?

    Hi Kirants,

    What happen was, I create a CBitmap object and use select this bitmap object to the device context. So, all drawing that being done will be put into this CBitmap object.
    Code:
       if(m_bmpToDraw.CreateBitmap(width, height, planes, bpp, NULL))
       {
          m_bmpOld = m_pDC->SelectObject(&m_bmpToDraw);
          return TRUE;
       }
    As you can see, if my m_pDC->GetDeviceCaps(LOGPIXELSX) or m_pDC->GetDeviceCaps(LOGPIXELSY) has resolution of 96x96, the image resolution produced will be 96x96. I need the image resolution to be 200x200 or 200x98 etc...

    How to achive this?

    Thanks again for your help in advance...

    Cheers
    Last edited by ryu; September 22nd, 2005 at 08:49 PM.

  7. #7

    Re: How to create DC with specific resolution?

    I don't think you can use this way to create DC with specific resolution.

    Andy

    ---------------------------------------------------------------------------------
    XD++ MFC/C++ Flow/Diagram Library (Full Visio 2003 Like,100% Source Code Kit) -- http://www.********.net

  8. #8
    Join Date
    Oct 2004
    Posts
    481

    Re: How to create DC with specific resolution?

    Hi Andy,

    Is there any workaround on this problem?

    Cheers

  9. #9
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: How to create DC with specific resolution?

    Quote Originally Posted by ryu
    I need the image resolution to be 200x200 or 200x98 etc...
    Do you mean, you want the bitmap to be of 200 pixel width and 98 pixel height ?

  10. #10
    Join Date
    Oct 2004
    Posts
    481

    Re: How to create DC with specific resolution?

    Hi Kirants,

    No... I mean the image resolution need to be 200dpi (in width) and 98dpi (in height). The image size can be any size (such as: 1000pixelx1000pixel, etc...).

    You can check the image resolution by:
    - open the image in Microsoft Paint (Start + Program + Accessories + Paint)
    - Click on Image + Attributes (or press CTRL+E)
    - You will see the image attribute resolution.

    Thanks again for any helps in advance...

    Cheers
    Last edited by ryu; September 22nd, 2005 at 10:27 PM.

  11. #11
    Join Date
    Oct 2004
    Posts
    481

    Re: How to create DC with specific resolution?

    Anyone...??? Guru...??

  12. #12
    Join Date
    Oct 2004
    Posts
    481

    Re: How to create DC with specific resolution?

    GURU...??? Anyone??? GURU...??? Please help...

  13. #13
    Join Date
    Jun 2005
    Posts
    1,255

    Re: How to create DC with specific resolution?

    I understand what you mean, but I am afraid there is no solution.

    A DC (Display Context) is associated to a display (or printer) device. The LOGPIXELSX/Y settings are linked to a device and its driver.

    Instead of CreateCompatibleDC(), you can do CreateDC(). See the documentation at http://msdn.microsoft.com/library/de...vcons_5g83.asp.
    You'll see that you need to give the name of a device and the name of a driver. If you have a device with a driver able to handle 200x96dpi, it's good for you.
    You may specify a DEVMODE structure containing settings of devices. See http://msdn.microsoft.com/library/de...tspol_8nle.asp. But you cannot choose settings that are not allowed by your device and its driver.

  14. #14
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: How to create DC with specific resolution?

    Once you have a DC with a bitmap selected into it, you know the DC is running at 96 (or whetever) DPI. You know this needs to map onto a x * y bitmap.

    You can calculate scaling coordinates for the DC in a call to SetWorldTransform, which will scale all commands from one to the other. This means that you could in effect chnage the 96DPI to whatever DPI you need.


    Its not something I have done, but I believe you could get it to work.
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  15. #15
    Join Date
    Oct 2004
    Posts
    481

    Re: How to create DC with specific resolution?

    Hi RogerAllen,

    Thanks for replying

    Now, I am getting somewhere. Before I do not know where to look. But is it possible to explain more in details?

    If I draw a rectangle:
    Code:
    m_pDC->Rectangle(10, 10, 100, 100);
    How can I make this rectangle being draw using 200dpi instead of 96dpi?

    Thanks again for any help, in advance...

    Cheers

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured