-
Feb 21st, 2012, 03:18 AM
#1
[RESOLVED] GdiPlus - Is possible to change scale?
I changed my picturebox scale to be like in maths (X,Y) with 0 in the exact center, so left half of the pbox has negative x, on the right part x is positive, it's the same for Y values: top half is positive and down half is negative, the code to make this scale is:
Code:
With Me.Picture1
.ScaleWidth = 50
.ScaleHeight = -50
.ScaleLeft = -.ScaleWidth \ 2
.ScaleTop = Abs(.ScaleHeight \ 2)
End With
I can draw formulas in the PictueBox using Line method, everything is working fine, but now I want to apply antialiasing so changed to GdiPlus. Using (and twiking a bit) the example i found here i can draw lines using GDI, the problem is it won't respect the PictureBox's scale, i think by default it has cero on the top/left corner and also the unit is much smaller than mine, so: It there any "direct way" to tell GDI what's the scale and place cero in the center for X and Y?
If there is no way to do it then i'll make the conversion myself but maybe GDI allows to set a scale like this.
Thanks.
-
Feb 21st, 2012, 10:40 AM
#2
Re: GdiPlus - Is possible to change scale?
GDI+ does have some functions to translate/transform points. Specifically, these may be useful/applicable: GdipTranslateWorldTransform, GdipTransformPoints, GdipCreateMatrix2
But I think it is a bit easier (less code) to build the transformation yourself...
Code:
' form-level variables
Private m_TranslateX As Single
Private m_TranslateY As Single
Private m_ScaleX As Single
Private m_ScaleY As Single
' example of setting it up
With Me.Picture1
m_TranslateX = ScaleX(.ScaleWidth, .ScaleMode, vbPixels) ' width in pixels
m_TranslateY = ScaleY(.ScaleHeight, .ScaleMode, vbPixels) ' height in pixels
m_ScaleX = m_TranslateX / 50 ' 50 = .ScaleWidth
m_ScaleY = m_TranslateY / -50 ' -50 = .ScaleHeight
m_TranslateX = m_TranslateX / 2 ' horizontal offset to 0,0 centered
m_TranslateY = m_TranslateY / 2 ' vertical offset to 0,0 centered
.ScaleWidth = 50
.ScaleHeight = -50
.ScaleLeft = -.ScaleWidth \ 2
.ScaleTop = Abs(.ScaleHeight \ 2)
End With
' sample using the translation/transformation
DrawGradientLine Picture1.Hdc, (x1 * m_ScaleX + m_TranslateX), (y1 * m_ScaleY + m_TranslateY), _
(x2 * m_ScaleX + m_TranslateX), (y2 * m_ScaleY + m_TranslateY), _
&HFF0D0080, &HFFC8C9DD, 2, FillModeWinding, True
Edited: Tip. If using a pen size larger than 1.5 & FillModeAlternate, use that code's DrawGradientLine not the DrawGradientLineI routine else rounding errors can result in unexpected line lengths with angled lines
Last edited by LaVolpe; Feb 21st, 2012 at 12:04 PM.
-
Feb 21st, 2012, 04:46 PM
#3
Re: GdiPlus - Is possible to change scale?
Thanks Lavolpe, it's working very well.
-
Feb 21st, 2012, 07:35 PM
#4
Re: GdiPlus - Is possible to change scale?
Cool. Don't forget to resolve the thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|