Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
Go Back  Xtreme Visual Basic Talk > > > Positioning a STRETCHED graphic path


Reply
 
Thread Tools Display Modes
  #1  
Old 03-07-2016, 01:08 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default Positioning a STRETCHED graphic path


My program requires that I stretch a path various degrees in relation to lines that are drawn on the graphic.

Better explained in the attached image.
The first pair of lines is 50 pixels apart and the 2nd pair is 250 pixels apart.
The path is a 6 point path that forms a simple bracket.
The left-most bracket is the original unaltered bracket. The next bracket is stretched to 68%, and the third to 335%
The 2nd and 3rd brackets are sized according to the spacing of the lines.

My problem is I can't figure out a generic formula to use for:
- the stretchY variable.
- offsets for the GdipTranslateMatrix function

The line spacing is determined by the user at run-time, as well as the positioning of the line pairs, so nothing can be pre-calculated.

Any help would be appreciated.

Code:
Private Sub Command1_Click()

    Picture1.Cls

    Dim graphics As Long
    stat = GdipCreateFromHDC(Picture1.hdc, graphics)
    stat = GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias)

    Dim j As Long
    Dim blackPen As Long
    stat = GdipCreatePen1(&HFF000000, 1, UnitPixel, blackPen)
    Dim blackBrush As Long
    stat = GdipCreateSolidFill(&HFF000000, blackBrush)

    
    Call LoadPath01

    'draw 1st pair of lines  50 pixels apart
    stat = GdipDrawLine(graphics, blackPen, 125, 50, 275, 50)
    stat = GdipDrawLine(graphics, blackPen, 125, 100, 275, 100)
    
    'draw 2nd pair of lines 250 pixels apart
    stat = GdipDrawLine(graphics, blackPen, 350, 50, 500, 50)
    stat = GdipDrawLine(graphics, blackPen, 350, 300, 500, 300)

    Dim scaleFac As Single
    scaleFac = 0.25
    
    Dim stretchY As Single
    Dim matrix As Long

    'draw bracket unstretched
    Dim pathToDraw As Long
    'stat = GdipCreatePath(FillModeAlternate, pathToDraw) 'see other
    stat = GdipCreatePath(FillModeWinding, pathToDraw)
    stat = GdipAddPathPath(pathToDraw, Path10, 0)
    'stat = GdipDeleteMatrix(matrix)
    stat = GdipCreateMatrix(matrix)
    stretchY = 1
    stat = GdipScaleMatrix(matrix, scaleFac, scaleFac * stretchY, MatrixOrderAppend)
    stat = GdipTranslateMatrix(matrix, -30, -50, MatrixOrderAppend)
    stat = GdipTransformPath(pathToDraw, matrix)
    stat = GdipFillPath(graphics, blackBrush, pathToDraw)

    'draw bracket stretched to match 1st pair of lines
    stat = GdipResetPath(pathToDraw)
    stat = GdipAddPathPath(pathToDraw, Path10, 0)
    stat = GdipDeleteMatrix(matrix)
    stat = GdipCreateMatrix(matrix)
    stretchY = 0.68
    stat = GdipScaleMatrix(matrix, scaleFac, scaleFac * stretchY, MatrixOrderAppend)
    stat = GdipTranslateMatrix(matrix, 55, -1, MatrixOrderAppend)
    stat = GdipTransformPath(pathToDraw, matrix)
    stat = GdipFillPath(graphics, blackBrush, pathToDraw)

    'draw bracket stretched to match 2nd pair of lines
    stat = GdipResetPath(pathToDraw)
    stat = GdipAddPathPath(pathToDraw, Path10, 0)
    stat = GdipCreateMatrix(matrix)
    stretchY = 3.35
    stat = GdipScaleMatrix(matrix, scaleFac, scaleFac * stretchY, MatrixOrderAppend)
    stat = GdipTranslateMatrix(matrix, 280, -202, MatrixOrderAppend)
    stat = GdipTransformPath(pathToDraw, matrix)
    stat = GdipFillPath(graphics, blackBrush, pathToDraw)

    ' Cleanup
    stat = GdipDeletePath(Path10)
    stat = GdipDeletePath(pathToDraw)
    stat = GdipDeleteBrush(blackBrush)
    stat = GdipDeletePen(blackPen)
    stat = GdipDeleteGraphics(graphics)
    
    Picture1.Refresh
    
End Sub
Attached Images
File Type: png StretchPath.png (2.4 KB, 3 views)

Last edited by mms; 03-07-2016 at 01:16 PM.
Reply With Quote
Reply

Tags
stat, stretchy, dim, scalefac, lines, bracket, matrixorderappend, pair, blackpen, pathtodraw, blackbrush, draw, gdipdrawlinegraphics, stretched, pixels, 2nd, matrix, path, gdipaddpathpathpathtodraw, gdipfillpathgraphics, path10, gdipcreatematrixmatrix, gdipscalematrixmatrix, gdiptranslatematrixmatrix, match


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
 
Positioning a STRETCHED graphic path
Positioning a STRETCHED graphic path
 
-->