Results 1 to 29 of 29

Thread: DEMO: GDI+...Advanced pens and colors

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    DEMO: GDI+...Advanced pens and colors

    Feast your eyes...

    (usual drill, setup a form with a button and paste this code in)

    VB Code:
    1. imports system.drawing.drawing2d
    2. '........
    3.  
    4. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.  
    6.         Dim g As Graphics = Me.CreateGraphics
    7.  
    8.         'shape of the pen stroke
    9.         Dim curve() As Point = New Point(6) _
    10.           { _
    11.           New Point(10, 10), _
    12.           New Point(20, 60), _
    13.           New Point(90, 240), _
    14.           New Point(280, 210), _
    15.           New Point(60, 60), _
    16.           New Point(30, 180), _
    17.           New Point(300, 300) _
    18.           }
    19.  
    20.         'define a fancy color gradient
    21.         Dim ink As PathGradientBrush = New PathGradientBrush(curve)
    22.  
    23.         '###########
    24.         'temporary object for setting up the color gradient
    25.         Dim blender As ColorBlend = New ColorBlend(curve.Length)
    26.         blender.Colors = New Color(6) {Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet}
    27.         blender.Positions = New Single(6) {}
    28.         For i As Integer = 0 To 6
    29.             blender.Positions(i) = i * (1.0F / 6.0F)          'equally space each colour along the path outline
    30.         Next i
    31.         ink.InterpolationColors = blender
    32.         '###########
    33.  
    34.         Dim CoolPen As Pen = New Pen(ink, 20)         'create a customisable pen object
    35.         CoolPen.CompoundArray() = New Single() {0, 0.2, 0.4, 0.5, 0.75, 1}        'the 3 striped pen instead of a single "nib"
    36.  
    37.         g.DrawBeziers(CoolPen, curve)      'go!
    38.  
    39.     End Sub
    Last edited by wossname; Jun 15th, 2005 at 09:15 AM.
    I don't live here any more.

  2. #2

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    Note: Antialiasing doesn't have any effect on PathGradientBrushes, not do transparent colors apparently.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Maine, USA
    Posts
    277

    Re: DEMO: GDI+...Advanced pens and colors

    Cool!

    Even if you are not going to write a book, will you put this stuff on a website?
    Preferably as tutorials.
    <deis> I turn on god mode when I program
    <deis> I just call it .NET


    If my post was helpful, please Rate it

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: DEMO: GDI+...Advanced pens and colors

    Nice demo.

    Areas filled using a PathGradientBrush object are rendered the same way (aliased) regardless of the smoothing mode.
    Last edited by RobDog888; Jun 15th, 2005 at 11:49 AM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    I've already started the book, you may be interested to hear. Or more specifically I have written a program that generates nice images for my chapter headings

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: DEMO: GDI+...Advanced pens and colors

    Now how about getting rid of that x-mas hat. Poor Desi.
    Her eyes are red with rage from having to wear it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Maine, USA
    Posts
    277

    Re: DEMO: GDI+...Advanced pens and colors

    Quote Originally Posted by wossname
    I've already started the book, you may be Thrilled! to hear.
    Yay for Wossy
    <deis> I turn on god mode when I program
    <deis> I just call it .NET


    If my post was helpful, please Rate it

  8. #8

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    Color test: Should be greyscale and transparent...
    Attached Images Attached Images  
    I don't live here any more.

  9. #9
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Maine, USA
    Posts
    277

    Re: DEMO: GDI+...Advanced pens and colors

    Where did you learn GDI+...?
    <deis> I turn on god mode when I program
    <deis> I just call it .NET


    If my post was helpful, please Rate it

  10. #10

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    The same place I learned everything else I know about programming - home

    I'm self taught on pretty much everything, if a new topic is too big to just dive into, I tend to buy a book about it (or hit the library first). I generally don't bother looking for online tutorials because they are always useless in my experience.

    Easiest way to learn programming topics is to look at the tools available to you - Books, MSDN and in particular the much overlooked Intellisense which is an absolute life saver, it gives you a good lead on where to research next.

    Anyway there will be a short history of my coding career in the book
    I don't live here any more.

  11. #11
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: DEMO: GDI+...Advanced pens and colors

    I will buy the book ....

    hurray for wossname!

  12. #12

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    Don't get too excited, I haven't even written the introduction yet

  13. #13
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: DEMO: GDI+...Advanced pens and colors

    Awww got my hopes up there....

    I think alot of people (inc me) would buy your lessons/code/samples/tutorials if you ever make it available

  14. #14

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    ...but I have designed the chapter headings (see post 8), sketched out a chapter plan, organised a bibliography and an acknowledgements page. All I need is a few months, a publisher and a target audience.

    Could it possibly be any easier?


  15. #15
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Maine, USA
    Posts
    277

    Re: DEMO: GDI+...Advanced pens and colors

    Huh, I find tutorials to be very helpful mostly.
    And yeah, I use intellisense a lot
    <deis> I turn on god mode when I program
    <deis> I just call it .NET


    If my post was helpful, please Rate it

  16. #16
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: DEMO: GDI+...Advanced pens and colors

    Check this out.

    Same thing, form with a button.

    VB Code:
    1. Imports System.Net
    2. Imports System.IO
    3. Imports System.Drawing.Imaging
    4. '....................
    5.  
    6.    Const Tollerance As Single = 0.2F
    7.     Private Sub Sep(ByVal InVal1 As Integer, ByVal InVal2 As Integer, ByRef OutVal1 As Integer, ByRef OutVal2 As Integer)
    8.         If InVal1 > InVal2 Then
    9.             OutVal1 = InVal2
    10.             OutVal2 = InVal1
    11.         Else
    12.             OutVal1 = InVal1
    13.             OutVal2 = InVal2
    14.         End If
    15.         ApplyTol(OutVal1, 1 - Tollerance)
    16.         ApplyTol(OutVal2, 1 + Tollerance)
    17.     End Sub
    18.  
    19.     Private Sub ApplyTol(ByRef Val As Integer, ByVal Tol As Single)
    20.         Val = CInt(Val * Tol)
    21.         If Val < 0 Then Val = 0
    22.         If Val > 255 Then Val = 255
    23.     End Sub
    24.  
    25.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    26.         Me.WindowState = FormWindowState.Maximized
    27.         Dim gr As Graphics = Me.CreateGraphics
    28.         Dim mImage As Bitmap
    29.  
    30.         Try '   download wossnames avatar
    31.             Dim Req As WebRequest = WebRequest.Create("http://www.vbforums.com/image.php?u=37340&dateline=1117135946")
    32.             Dim Resp As WebResponse = Req.GetResponse
    33.             Dim ImgStream As Stream = Resp.GetResponseStream
    34.             mImage = CType(Image.FromStream(ImgStream), Bitmap)
    35.             Resp.Close()
    36.             ImgStream.Close()
    37.         Catch : Exit Sub : End Try ' don't care
    38.  
    39.         '   define drawing location
    40.         Dim UpLeftPoint As New Point(Me.Width \ 2 - mImage.Width * 2, _
    41.                                      Me.Height \ 2 - mImage.Height * 2)
    42.         Dim DrawingSize As New Size(mImage.Width * 4, mImage.Height * 4)
    43.  
    44.         Dim UpLeftShadowPoint As New Point(UpLeftPoint.X + 15, UpLeftPoint.Y + 15)
    45.  
    46.         '   show the original
    47.         gr.DrawImage(mImage, New Rectangle(UpLeftPoint, DrawingSize))
    48.         '   wait a while
    49.         Threading.Thread.Sleep(2000)
    50.         gr.Clear(Me.BackColor)
    51.  
    52.         '   sample two colors for the colorkey in order to remove the background
    53.         Dim MaskColor1 As Color = mImage.GetPixel(mImage.Width - 7, mImage.Height - 7)
    54.         Dim MaskColor2 As Color = mImage.GetPixel(0, 0)
    55.  
    56.         Dim R1, R2, G1, G2, B1, B2 As Integer
    57.         '   create a low and a high color from the samples
    58.         '   would like to know if there is a better way.
    59.         Sep(MaskColor1.R, MaskColor2.R, R1, R2)
    60.         Sep(MaskColor1.G, MaskColor2.G, G1, G2)
    61.         Sep(MaskColor1.B, MaskColor2.B, B1, B2)
    62.         Dim MaskColorLow As Color = Color.FromArgb(R1, G1, B1)
    63.         Dim MaskColorHigh As Color = Color.FromArgb(R2, G2, B2)
    64.  
    65.         '   create attributes for the shadow
    66.         Dim AttrShadow As New ImageAttributes
    67.         '   R, G and B components in the low color must all be lower
    68.         '   than those components in the high color
    69.         AttrShadow.SetColorKey(MaskColorLow, MaskColorHigh)
    70.         '   make it transparent
    71.         Dim AttrShadowMatrixItems As Single()() = { _
    72.                                                    New Single() {1, 0, 0, 0, 0}, _
    73.                                                    New Single() {0, 1, 0, 0, 0}, _
    74.                                                    New Single() {0, 0, 1, 0, 0}, _
    75.                                                    New Single() {0, 0, 0, 0.3F, 0}, _
    76.                                                    New Single() {0, 0, 0, 0, 1} _
    77.                                                   }
    78.         Dim colorMatrix As New ColorMatrix(AttrShadowMatrixItems)
    79.         AttrShadow.SetColorMatrix(colorMatrix)
    80.         '   create attributes for foreground pic
    81.         Dim AttrFore As New ImageAttributes
    82.         AttrFore.SetColorKey(MaskColorLow, MaskColorHigh)
    83.  
    84.         '   draw shadow
    85.         gr.DrawImage( _
    86.                      mImage, _
    87.                      New Rectangle(UpLeftShadowPoint, _
    88.                                    DrawingSize), _
    89.                      0, _
    90.                      0, _
    91.                      mImage.Width, _
    92.                      mImage.Height, _
    93.                      GraphicsUnit.Pixel, _
    94.                      AttrShadow _
    95.                     )
    96.         '   draw pic
    97.         gr.DrawImage(mImage, _
    98.                      New Rectangle(UpLeftPoint, DrawingSize), _
    99.                      0, _
    100.                      0, _
    101.                      mImage.Width, _
    102.                      mImage.Height, _
    103.                      GraphicsUnit.Pixel, _
    104.                      AttrFore _
    105.                     )
    106.     End Sub
    Last edited by grilkip; Jul 14th, 2005 at 04:27 PM.

  17. #17

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    Do you have a link to any info about how color matrixes work? MSDN has nothing useful.
    I don't live here any more.

  18. #18
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: DEMO: GDI+...Advanced pens and colors

    Quote Originally Posted by wossname
    Do you have a link to any info about how color matrixes work? MSDN has nothing useful.
    Nope, the matrix I used was copied directly out of MSDN, with one change.
    And I haven't a clue as to how it works.
    Last edited by grilkip; Jun 19th, 2005 at 09:20 AM.

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: DEMO: GDI+...Advanced pens and colors

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  20. #20

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    well done Rob, that's what I meant by "MSDN has nothing useful"

    Basically that page just says "this is an array, get on with it".

    I guess MS assume that people that need to use color matrices already know how they work. Its a bit of a pain really.
    I don't live here any more.

  21. #21
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: DEMO: GDI+...Advanced pens and colors


  22. #22

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    That's about the best I've seen so far.

    But nobody seems to ever mention why the diagonal line of numbers (see pic)is used, why not just stick all the numbers on the top row? I don't understand the significance of difference positions in the 2 dimensional array.
    Attached Images Attached Images  
    Last edited by wossname; Jun 20th, 2005 at 09:40 AM.

  23. #23
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: DEMO: GDI+...Advanced pens and colors

    When you visualize the matrix, that becomes clear. Look how the first "1" corresponds to the same component on both lines and so on.

    PHP Code:
    _RGBAw
    R1
    G 1
    B  1
    A   1
    w    1 
    In the sample program I posted earlier (position) A,A = 0.3 so Alpha in * 0.3 = Alpha out

    Edit: well that doesn't look right, the spacings are messed up, but you get the idea.
    Last edited by grilkip; Jun 20th, 2005 at 12:42 PM.

  24. #24

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    ok so if I put...

    Code:
    ...
    New Single() {0.1, 0, 0, 0, 0}, _
    New Single() {0.1, 0, 0, 0, 0}, _
    New Single() {0.1, 0, 0, 0, 0}, _
    New Single() {0, 0, 0, 1, 0}, _
    New Single() {0, 0, 0, 0, 1}
    ...
    Then

    RedOut = (0.1*RedIn) + (0.1*GreenIn) +(0.1*BlueIn)

    ?
    I don't live here any more.

  25. #25
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: DEMO: GDI+...Advanced pens and colors

    That's how I think it works yes, but the biggest question to me is how to use the "w" component?

    edit: I'm still wondering which is in and which is out by the way.

    Oh and:
    according to my math teacher:

    RedOut = (0.1*RedIn) + (0.1*GreenIn) +(0.1*BlueIn)

    should be:

    RedOut = 0.1*RedIn + 0.1*GreenIn + 0.1*BlueIn

    Zing!
    Last edited by grilkip; Jun 20th, 2005 at 09:59 AM.

  26. #26

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    The W component doesn't do anything apparently, you are supposed to leave it at 1.

    I think the Color In comes in from the left, gets multiplied by the normalised matrix values. Then you add up each column and the 5 totals correspond to RGBAW --> (Color Out).

    This is quite interesting. I shall investigate this for the book tonight.

  27. #27

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    Quote Originally Posted by grilkip
    That's how I think it works yes, but the biggest question to me is how to use the "w" component?

    edit: I'm still wondering which is in and which is out by the way.

    Oh and:
    according to my math teacher:

    RedOut = (0.1*RedIn) + (0.1*GreenIn) +(0.1*BlueIn)

    should be:

    RedOut = 0.1*RedIn + 0.1*GreenIn + 0.1*BlueIn

    Zing!
    The thing your maths teacher suggested is exactly equivalent to what I put.

    There is no need to remove parentheses if they aid clarity of an equation. I find the brackets version easier to read personally. I always use parentheses in code.

  28. #28

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: DEMO: GDI+...Advanced pens and colors

    Just thrown this spreadsheet together.

    I think it works, might be useful to someone.
    Attached Files Attached Files
    I don't live here any more.

  29. #29
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: DEMO: GDI+...Advanced pens and colors

    The more I understand about this thing, the more I start to like it.

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