VB.Net by API/System.Drawing/Color — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:49, 26 мая 2010

Color.Brightness

  
        
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class GetSaturationGetBrightness
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
public class Form1
  Inherits System.Windows.Forms.Form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim g As Graphics = Me.CreateGraphics()
        " Create a color 
        Dim clr As Color = Color.FromArgb(255, 200, 0, 100)
        " Get hue, saturation, and brightness components
        Dim h As Single = clr.GetHue()
        Dim s As Single = clr.GetSaturation()
        Dim v As Single = clr.GetBrightness()
        Dim str As String = "Hue: " + h.ToString() + ControlChars.Lf + "Saturation: " + s.ToString() + ControlChars.Lf + "Brightness: " + v.ToString()
        " Display data
        g.DrawString(str, New Font("verdana", 12), Brushes.Blue, 50, 50)
        " Dispose
        g.Dispose()

  End Sub
  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class


Color.FromArgb

  
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class ColorCreation
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
public class Form1
  Inherits System.Windows.Forms.Form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim g As Graphics = Me.CreateGraphics()
        Dim redColor As Color = Color.FromArgb(120, 255, 0, 0)
        Dim blueColor As Color = Color.FromName("Blue")
        Dim greenColor As Color = Color.FromKnownColor(KnownColor.Green)
        Dim tstColor As Color = Color.Empty
        If greenColor.IsEmpty Then
            tstColor = Color.DarkGoldenrod
        End If
        Dim redBrush As New SolidBrush(redColor)
        Dim blueBrush As New SolidBrush(blueColor)
        Dim greenBrush As New SolidBrush(greenColor)
        Dim greenPen As New Pen(greenBrush, 4)
        g.FillEllipse(redBrush, 10, 10, 50, 50)
        g.FillRectangle(blueBrush, 60, 10, 50, 50)
        g.DrawLine(greenPen, 20, 60, 200, 60)
        Console.WriteLine("Color Name :" + blueColor.Name + ", A:" + blueColor.A.ToString() + ", R:" + blueColor.R.ToString() + ", B:" + blueColor.B.ToString() + ", G:" + blueColor.G.ToString())
        redBrush.Dispose()
        blueBrush.Dispose()
        greenBrush.Dispose()
        greenPen.Dispose()
        g.Dispose()
  End Sub
  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class


Color.FromArgb 2

  

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Math
public class CreateBitmap
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
public class Form1
  Inherits System.Windows.Forms.Form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim bm As New Bitmap("yourfile.jpg")
        Dim new_bm As New Bitmap(bm)
        bm.Dispose()
        Dim gr As Graphics = Graphics.FromImage(new_bm)
        gr.DrawEllipse(Pens.White, 0, 0, new_bm.Width - 1, new_bm.Height - 1)
  
        e.Graphics.DrawImage(new_bm,0,0,400,400)
  End Sub
    Private Sub InvertImage(ByVal bm As Bitmap)
        For y As Integer = 0 To bm.Height - 1
            For x As Integer = 0 To bm.Width - 1
                Dim clr As Color = bm.GetPixel(x, y)
                clr = Color.FromArgb(255,255 - clr.R, 255 - clr.G, 255 - clr.B)
                bm.SetPixel(x, y, clr)
            Next x
        Next y
    End Sub
  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class


Color.FromArgb(Int r, Int g, Int b, Int alpha)

  

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class GDIObjectsCreateGraphicColorFromRGBAlpha
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim canvas As Graphics = e.Graphics
        Dim colorBackground As Color =  Color.FromArgb(127, 0, 255, 123)
        canvas.Clear(colorBackground)
        
        canvas = Nothing
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.SuspendLayout()
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(610, 328)
        Me.Name = "Form1"
        Me.Text = "Creating Graphics Objects (Color, Pen, Font, Brush)"
        Me.ResumeLayout(False)
    End Sub
End Class


Color.FromKnownColor

  
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class KnownColorActiveBorder
   public Shared Sub Main
        Console.WriteLine(Color.FromKnownColor(KnownColor.ActiveBorder))
   End Sub
End class


Color.FromName

  
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class ColorCreation
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
public class Form1
  Inherits System.Windows.Forms.Form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim g As Graphics = Me.CreateGraphics()
        Dim redColor As Color = Color.FromArgb(120, 255, 0, 0)
        Dim blueColor As Color = Color.FromName("Blue")
        Dim greenColor As Color = Color.FromKnownColor(KnownColor.Green)
        Dim tstColor As Color = Color.Empty
        If greenColor.IsEmpty Then
            tstColor = Color.DarkGoldenrod
        End If
        Dim redBrush As New SolidBrush(redColor)
        Dim blueBrush As New SolidBrush(blueColor)
        Dim greenBrush As New SolidBrush(greenColor)
        Dim greenPen As New Pen(greenBrush, 4)
        g.FillEllipse(redBrush, 10, 10, 50, 50)
        g.FillRectangle(blueBrush, 60, 10, 50, 50)
        g.DrawLine(greenPen, 20, 60, 200, 60)
        Console.WriteLine("Color Name :" + blueColor.Name + ", A:" + blueColor.A.ToString() + ", R:" + blueColor.R.ToString() + ", B:" + blueColor.B.ToString() + ", G:" + blueColor.G.ToString())
        redBrush.Dispose()
        blueBrush.Dispose()
        greenBrush.Dispose()
        greenPen.Dispose()
        g.Dispose()
  End Sub
  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class


Color.FromWin32

  
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class FromHtml
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
public class Form1
  Inherits System.Windows.Forms.Form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim g As Graphics = Me.CreateGraphics()
        " Translate colors
        Dim win32Color As Color = ColorTranslator.FromWin32(&HFF0033)
        Dim htmlColor As Color = ColorTranslator.FromHtml("#00AAFF")
        " Using colors
        Dim redBrush As New SolidBrush(win32Color)
        Dim blueBrush As New SolidBrush(htmlColor)
        " Drawing GDI+ objects
        g.FillEllipse(redBrush, 10, 10, 50, 50)
        g.FillRectangle(blueBrush, 60, 10, 50, 50)
        "Dispose
        redBrush.Dispose()
        blueBrush.Dispose()
        g.Dispose()
  End Sub
  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class


Color.Hue

  
        
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class GetSaturationGetBrightness
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
public class Form1
  Inherits System.Windows.Forms.Form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim g As Graphics = Me.CreateGraphics()
        " Create a color 
        Dim clr As Color = Color.FromArgb(255, 200, 0, 100)
        " Get hue, saturation, and brightness components
        Dim h As Single = clr.GetHue()
        Dim s As Single = clr.GetSaturation()
        Dim v As Single = clr.GetBrightness()
        Dim str As String = "Hue: " + h.ToString() + ControlChars.Lf + "Saturation: " + s.ToString() + ControlChars.Lf + "Brightness: " + v.ToString()
        " Display data
        g.DrawString(str, New Font("verdana", 12), Brushes.Blue, 50, 50)
        " Dispose
        g.Dispose()

  End Sub
  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class


Color.Saturation

  
        
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class GetSaturationGetBrightness
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
public class Form1
  Inherits System.Windows.Forms.Form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim g As Graphics = Me.CreateGraphics()
        " Create a color 
        Dim clr As Color = Color.FromArgb(255, 200, 0, 100)
        " Get hue, saturation, and brightness components
        Dim h As Single = clr.GetHue()
        Dim s As Single = clr.GetSaturation()
        Dim v As Single = clr.GetBrightness()
        Dim str As String = "Hue: " + h.ToString() + ControlChars.Lf + "Saturation: " + s.ToString() + ControlChars.Lf + "Brightness: " + v.ToString()
        " Display data
        g.DrawString(str, New Font("verdana", 12), Brushes.Blue, 50, 50)
        " Dispose
        g.Dispose()

  End Sub
  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class