Jun 15th, 2005, 04:19 AM
#1
DEMO: GDI+...Advanced pens and colors
Feast your eyes...
(usual drill, setup a form with a button and paste this code in)
VB Code:
imports system.drawing.drawing2d
'........
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim g As Graphics = Me.CreateGraphics
'shape of the pen stroke
Dim curve() As Point = New Point(6) _
{ _
New Point(10, 10), _
New Point(20, 60), _
New Point(90, 240), _
New Point(280, 210), _
New Point(60, 60), _
New Point(30, 180), _
New Point(300, 300) _
}
'define a fancy color gradient
Dim ink As PathGradientBrush = New PathGradientBrush(curve)
'###########
'temporary object for setting up the color gradient
Dim blender As ColorBlend = New ColorBlend(curve.Length)
blender.Colors = New Color(6) {Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet}
blender.Positions = New Single(6) {}
For i As Integer = 0 To 6
blender.Positions(i) = i * (1.0F / 6.0F) 'equally space each colour along the path outline
Next i
ink.InterpolationColors = blender
'###########
Dim CoolPen As Pen = New Pen(ink, 20) 'create a customisable pen object
CoolPen.CompoundArray() = New Single() {0, 0.2, 0.4, 0.5, 0.75, 1} 'the 3 striped pen instead of a single "nib"
g.DrawBeziers(CoolPen, curve) 'go!
End Sub
Last edited by wossname; Jun 15th, 2005 at 09:15 AM .
I don't live here any more.
Jun 15th, 2005, 09:16 AM
#2
Re: DEMO: GDI+...Advanced pens and colors
Note: Antialiasing doesn't have any effect on PathGradientBrushes, not do transparent colors apparently.
Jun 15th, 2005, 11:12 AM
#3
Hyperactive Member
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
Jun 15th, 2005, 11:46 AM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Jun 15th, 2005, 12:26 PM
#5
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
Jun 15th, 2005, 12:35 PM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Jun 15th, 2005, 03:35 PM
#7
Hyperactive Member
Re: DEMO: GDI+...Advanced pens and colors
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
Jun 15th, 2005, 04:14 PM
#8
Re: DEMO: GDI+...Advanced pens and colors
Color test: Should be greyscale and transparent...
Attached Images
I don't live here any more.
Jun 15th, 2005, 07:21 PM
#9
Hyperactive Member
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
Jun 16th, 2005, 03:08 AM
#10
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.
Jun 16th, 2005, 08:07 AM
#11
Frenzied Member
Re: DEMO: GDI+...Advanced pens and colors
I will buy the book ....
hurray for wossname!
Jun 16th, 2005, 08:11 AM
#12
Re: DEMO: GDI+...Advanced pens and colors
Don't get too excited, I haven't even written the introduction yet
Jun 16th, 2005, 08:14 AM
#13
Frenzied Member
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
Jun 16th, 2005, 08:17 AM
#14
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?
Jun 17th, 2005, 09:14 AM
#15
Hyperactive Member
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
Jun 17th, 2005, 05:19 PM
#16
Fanatic Member
Re: DEMO: GDI+...Advanced pens and colors
Check this out.
Same thing, form with a button.
VB Code:
Imports System.Net
Imports System.IO
Imports System.Drawing.Imaging
'....................
Const Tollerance As Single = 0.2F
Private Sub Sep(ByVal InVal1 As Integer, ByVal InVal2 As Integer, ByRef OutVal1 As Integer, ByRef OutVal2 As Integer)
If InVal1 > InVal2 Then
OutVal1 = InVal2
OutVal2 = InVal1
Else
OutVal1 = InVal1
OutVal2 = InVal2
End If
ApplyTol(OutVal1, 1 - Tollerance)
ApplyTol(OutVal2, 1 + Tollerance)
End Sub
Private Sub ApplyTol(ByRef Val As Integer, ByVal Tol As Single)
Val = CInt(Val * Tol)
If Val < 0 Then Val = 0
If Val > 255 Then Val = 255
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.WindowState = FormWindowState.Maximized
Dim gr As Graphics = Me.CreateGraphics
Dim mImage As Bitmap
Try ' download wossnames avatar
Dim Req As WebRequest = WebRequest.Create("http://www.vbforums.com/image.php?u=37340&dateline=1117135946")
Dim Resp As WebResponse = Req.GetResponse
Dim ImgStream As Stream = Resp.GetResponseStream
mImage = CType(Image.FromStream(ImgStream), Bitmap)
Resp.Close()
ImgStream.Close()
Catch : Exit Sub : End Try ' don't care
' define drawing location
Dim UpLeftPoint As New Point(Me.Width \ 2 - mImage.Width * 2, _
Me.Height \ 2 - mImage.Height * 2)
Dim DrawingSize As New Size(mImage.Width * 4, mImage.Height * 4)
Dim UpLeftShadowPoint As New Point(UpLeftPoint.X + 15, UpLeftPoint.Y + 15)
' show the original
gr.DrawImage(mImage, New Rectangle(UpLeftPoint, DrawingSize))
' wait a while
Threading.Thread.Sleep(2000)
gr.Clear(Me.BackColor)
' sample two colors for the colorkey in order to remove the background
Dim MaskColor1 As Color = mImage.GetPixel(mImage.Width - 7, mImage.Height - 7)
Dim MaskColor2 As Color = mImage.GetPixel(0, 0)
Dim R1, R2, G1, G2, B1, B2 As Integer
' create a low and a high color from the samples
' would like to know if there is a better way.
Sep(MaskColor1.R, MaskColor2.R, R1, R2)
Sep(MaskColor1.G, MaskColor2.G, G1, G2)
Sep(MaskColor1.B, MaskColor2.B, B1, B2)
Dim MaskColorLow As Color = Color.FromArgb(R1, G1, B1)
Dim MaskColorHigh As Color = Color.FromArgb(R2, G2, B2)
' create attributes for the shadow
Dim AttrShadow As New ImageAttributes
' R, G and B components in the low color must all be lower
' than those components in the high color
AttrShadow.SetColorKey(MaskColorLow, MaskColorHigh)
' make it transparent
Dim AttrShadowMatrixItems As Single()() = { _
New Single() {1, 0, 0, 0, 0}, _
New Single() {0, 1, 0, 0, 0}, _
New Single() {0, 0, 1, 0, 0}, _
New Single() {0, 0, 0, 0.3F, 0}, _
New Single() {0, 0, 0, 0, 1} _
}
Dim colorMatrix As New ColorMatrix(AttrShadowMatrixItems)
AttrShadow.SetColorMatrix(colorMatrix)
' create attributes for foreground pic
Dim AttrFore As New ImageAttributes
AttrFore.SetColorKey(MaskColorLow, MaskColorHigh)
' draw shadow
gr.DrawImage( _
mImage, _
New Rectangle(UpLeftShadowPoint, _
DrawingSize), _
0, _
0, _
mImage.Width, _
mImage.Height, _
GraphicsUnit.Pixel, _
AttrShadow _
)
' draw pic
gr.DrawImage(mImage, _
New Rectangle(UpLeftPoint, DrawingSize), _
0, _
0, _
mImage.Width, _
mImage.Height, _
GraphicsUnit.Pixel, _
AttrFore _
)
End Sub
Last edited by grilkip; Jul 14th, 2005 at 04:27 PM .
Jun 18th, 2005, 08:08 AM
#17
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.
Jun 19th, 2005, 08:58 AM
#18
Fanatic Member
Re: DEMO: GDI+...Advanced pens and colors
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 .
Jun 19th, 2005, 03:00 PM
#19
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Jun 20th, 2005, 04:15 AM
#20
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.
Jun 20th, 2005, 08:48 AM
#21
Fanatic Member
Re: DEMO: GDI+...Advanced pens and colors
Jun 20th, 2005, 09:33 AM
#22
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
Last edited by wossname; Jun 20th, 2005 at 09:40 AM .
Jun 20th, 2005, 09:42 AM
#23
Fanatic Member
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 .
Jun 20th, 2005, 09:49 AM
#24
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.
Jun 20th, 2005, 09:52 AM
#25
Fanatic Member
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 .
Jun 20th, 2005, 10:08 AM
#26
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.
Jun 20th, 2005, 10:12 AM
#27
Re: DEMO: GDI+...Advanced pens and colors
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.
Jun 20th, 2005, 10:50 AM
#28
Re: DEMO: GDI+...Advanced pens and colors
Just thrown this spreadsheet together.
I think it works, might be useful to someone.
Attached Files
I don't live here any more.
Jun 20th, 2005, 11:10 AM
#29
Fanatic Member
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
Forum Rules
Click Here to Expand Forum to Full Width