Results 1 to 4 of 4

Thread: [RESOLVED] GdiPlus - Is possible to change scale?

  1. #1

    Thread Starter
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Resolved [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.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: GdiPlus - Is possible to change scale?

    Thanks Lavolpe, it's working very well.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: GdiPlus - Is possible to change scale?

    Cool. Don't forget to resolve the thread
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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