Re: Update a graphic and save it
- From: "Mike D Sutton" <EDais@xxxxxxxx>
- Date: Wed, 24 May 2006 09:41:36 +0100
I must be doing something stupid, I can't get similar font sizes going to
the printer and the image. I am using the following code:
...
height = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72)
hfont = CreateFont(height, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Times New
Roman")
holdfont = SelectObject(hdc, hfont)
...
in a routine I call twice, once with the hdc from CreateCompatableDC(0), and
once with Printer.hdc. The font height seems to ba all out of wack. Is
there someting else I need to be doing?
The MulDiv() technique you're using to calculate the font size only works if the MM_TEXT mapping mode is set on the
target DC (unusual for a printer, which is capable of much higher resolutions than your standard display device.)
Since this method returns the height in pixels (which map 1:1 with device space), you can use the DPtoLP() API call to
convert this to logical space on the target DC:
'***
Private Declare Function DPtoLP Lib "GDI32.dll" (ByVal hDC As Long, _
ByRef lpPoint As PointAPI, ByVal nCount As Long) As Long
Private Declare Function SetMapMode Lib "GDI32.dll" ( _
ByVal hDC As Long, ByVal nMapMode As Long) As Long
Private Const MM_TEXT As Long = &H1
Private Type PointAPI
X As Long
Y As Long
End Type
....
Dim OldMapMode As Long
Dim PenSize As PointAPI
OldMapMode = SetMapMode(hdc, MM_TEXT)
PenSize.X = MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72)
If (OldMapMode <> MM_TEXT) Then
' Perform device to logical space mapping
Call DPtoLP(hdc, PenSize, 1)
Call SetMapMode(hdc, OldMapMode)
End If
PenSize.X = -Abs(PenSize.X)
' PenSize.X should now contain correct mapping for the target DC
'***
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
E-Mail: EDais@xxxxxxxx
WWW: Http://EDais.mvps.org/
.
- References:
- Re: Update a graphic and save it
- From: Mike D Sutton
- Re: Update a graphic and save it
- From: Terry
- Re: Update a graphic and save it
- From: Mike D Sutton
- Re: Update a graphic and save it
- From: Mike D Sutton
- Re: Update a graphic and save it
- Prev by Date: Re: display properties again
- Next by Date: Re: Common Interface for objects that expose VB-drawing-API
- Previous by thread: Re: Update a graphic and save it
- Next by thread: Re: Update a graphic and save it
- Index(es):
Relevant Pages
|
Loading