Results 1 to 4 of 4

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

Hybrid View

  1. #1
    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}

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