Home
Explore
Tags
Contribute
Home
»
VB.NET
»
GDI+ IN VB.NET
Blending in GDI+ using VB.NET
Posted in
VB.NET
|
GDI+ IN VB.NET
on
November 05, 2019
Tags:
blending
,
Blending in GDI+
,
GDI+
,
VB.NET
In this article I will explain about Blending in GDI+.
2910
If you have experience working with graphics you may have heard some terms related to blending. Blending, alpha blending, and color blending are a few of these. In general, blending refers to mixing or combining two colors: a source color and a background color. The resulting blended color is used to draw graphics shapes, line, and curves.
In this article blending is divided into three categories: color blending, alpha blending, and mixed blending. Color blending, which produces what are known as color gradients, involves drawing and filling graphics shapes, lines, and curves starting with a color at one end and finishing with another color at the other end. Figure 9.26 shows a good example of color blending.
Alpha blending is used to draw and fill transparent shapes, lines and curves. Pens and brushes are used to create alpha blending. First we create a pen or brush using the alpha component value as the color of a brush or pen, and then we use that brush or pen to fill and draw shapes, lines, and curves. Semitransparent or translucent graphics shapes, lines and curves are examples of alpha blending. For example, Figure 9.27 contains three lines with opaque and semitransparent colors, and a string with semitransparent color on top of an image, a perfect example of alpha blending.
FIGURE 9.26: Color blending examples
Mixed blending is probably a new concept to most readers. You won't find it mentioned in the MSDN documentation. Mixed blending is a combination of color and alpha blending. Figure 9.28 shows an example. If you run the sample code, you will see that the output consists of not only a transparent image, but also a color-blending sample.
FIGURE 9.27: Transparent graphics shapes in an image using alpha blending
FIGURE 9.28: Mixed blending effects
Color Blending
Gradient brushes play a major role in color blending. LinearGradientBrush and PathGradientBrush both represent brush object with color blending.
A linear gradient brush is a brush with two colors: a starting color and an ending color. A path gradient brush is used to fill graphics paths. Instead of starting a color from one end, the path gradient brush starts a color from the center of the path and ends with the second color at the outer boundary of the path.
A blend pattern is a combination of two colors (a starting color and an ending color) defined by factors and positions. The Blend class represents a blend patter in the .NET Framework. It provides two properties: Factors and Positions. The Factors property specifies the percentage of the starting color and the ending color to be used at the corresponding position. The Positions property specifies the percentages of distance for each gradation of color along the gradient line. The values of Factors and Positions must be between 0 and 1, where 0 represents the starting position and 1 represents the ending position. For example, 0.4f specifies that a point is 40 percent of the total distance from the starting point.
After creating a Blend object, you can attach it to a linear gradient brush by setting the Blend property of the LinearGradientBrush object. In Listing 9.18 we create a Blend object and its Factors and Positions properties, and then we set the Blend property of the LinearGradientBrush object. We can use this brush to fill graphics shapes.
LISTING 9.18: Creating Blend object and setting its Factors and Positions properties
Dim
brBrush
As
New
LinearGradientBrush(
New
Point(0, 0),
New
Point(50, 20), Color.Blue, Color.Red)
Dim
blend
As
New
Blend()
Dim
factArray
As
Single
() = {0.0F, 0.3F, 0.5F, 1.0F}
Dim
posArray
As
Single
() = {0.0F, 0.2F, 0.6F, 1.0F}
blend.Factors = factArray
blend.Positions = posArray
brBrush.Blend = blend
The ColorBlend class defines arrays of colors and positions used for interpolating color blending in a multicolor gradient. The Positions property, and array of floating point (values vary between 0.0 and 1.0), represents the position of the colors along a gradient line; and the Colors property, an array of Colors objects, represents the color to use at corresponding positions. Each positions defined in Positions has a corresponding color in the Colors array. Hence if six positions are defined in the Positions array the Colors array will have six Color objects.
To use a ColorBlend object, create the object and set its Positions and Colors properties, as shown in Listing 9.19. The InterpolationColors property of the LinearGradientBrush and PathGradientBrush classes uses the ColorBlend object.
LISTING 9.19: Creating a ColorBlend object and Setting its Colors and Positions properties
Dim
brBrush
As
New
LinearGradientBrush(
New
Point(0, 0),
New
Point(50, 20), Color.Blue, Color.Red)
' Create color and points arrays
Dim
clrArray
As
Color() = {Color.Red, Color.Blue, Color.Green, Color.Pink, Color.Yellow, Color.DarkTurquoise}
Dim
posArray
As
Single
() = {0.0F, 0.2F, 0.4F, 0.6F, 0.8F, 1.0F}
' Create a ColorBlend object and set its Colors and Positions properties
Dim
colorBlend
As
New
ColorBlend()
colorBlend.Colors = clrArray
colorBlend.Positions = posArray
brBrush.InterpolationColors = colorBlend
Hope the article would have helped you in understanding Blending in GDI+. Read other articles on GDI+ on the website.
Related Articles
Image Animation in VB.NET using GDI+
Drawing transparent Images and Shapes using Alpha Blending in VB.NET
WPF Grid Using VB.NET
Mixed Blending in GDI+ using VB.Net
Compositing Mode and Blending in VB.NET
GDI+ Brushes, Pens and Alpha Blending in VB.NET
GDI+ Alpha Blending and Images in VB.NET
Blending Using GDI+ LinearGradientBrush Objects in VB.NET
How to Set Focus on a Control in ASP.NET using VB.NET
How to create a File Upload in ASP.NET and VB.NET
Categories
ACTIVE DIRECTOTRY IN VB.NET
ALGORITHMS AND VB.NET
ARRAY IN VB.NET
ASP.NET AJAX IN VB.NET
ASP.NET USING VB.NET
ASSEMBLIES IN VB.NET
COM INTEROP IN VB.NET
CRYPTOGRAPHY IN VB.NET
CRYSTAL REPORTS IN VB.NET
DATABASE & DBA
DEPLOYMENT IN VB.NET
DESIGN & ARCHITECTURE
DIRECTX WITH VB.NET
ENTERPRISE DEVELOPMENT
FILE IN VB.NET
GAMES IN VB.NET
GDI+ IN VB.NET
GENERAL
LINQ WITH VB.NET
MOBILE DEV IN VB.NET
MULTITHREADING IN VB.NET
NETWORKIN WITH VB.NET
OFFICE AND VB.NET
PRINTING IN VB.NET
REMOTING IN VB.NET
REPORTS IN VB.NET
SECURITY IN VB.NET
SILVERLIGHT USING VB.NET
Speech in VB.NET
STRING IN VB.NET
TABLET PC
VB.NET ADO.NET
VB.NET ARTICLE
VB.NET EXCEPTION HANDLING
VB.NET FAQ
VB.NET HOW DO I
VB.NET LANGUAGE
VB.NET TUTORIALS
VB.NET WINDOWS SERVICES
VBA
VISUAL BASIC 10
VISUAL BASIC LANGUAGE
WCF WITH VB.NET
WEB CONTROL IN VB.NET
WEB DEV IN VB.NET
WEB FORM WITH VB.NET
WEB SERVICES IN VB.NET
WINDOWS CONTROLS
WINDOWS FORMS IN VB.NET
WORKFLOW IN VB.NET
WPF IN VB.NET
XAML IN VB.NET
XML IN VB.NET
More Articles
Stroke Caps in GDI+ using VB.NET
Basic GDI+ Objects in VB.NET
Transformation in GDI+ in VB.NET
Drawing Images in GDI+ in VB.NET
Working with GDI+ Fonts in VB.NET
GDI+ Pie Chart in VB.NET
Using GDI+ Graphics Paths in VB.NET
Drawing Lines in GDI+ using VB.NET
Printing Text in GDI+ using VB.NET
Designing GUI Applications in GDI+ using VB.NET
Printer Settings in GDI+ and VB.NET
No GDI Calls between GetHdc and ReleaseHdc in VB.NET
GDI Managed Environment in VB.NET
Use GDI+ System Brushes and Pens in VB.NET
Select Method carefully in GDI+ using VB.NET
Use Graphics Paths in GDI+ using VB.NET
SetStyle Method in GDI+ using VB.NET
Overriding the GDI+ OnPaint Method in VB.NET
GDI+ Double Buffering and Flicker-Free Drawing in VB.NET
GDi+ Scope and Type of Variable and Performance in VB.NET
Add GDI+ Paint Event Handler and Controls in VB.NET
Understanding the GDI+ Paint Event in VB.NET
Create ASP .NET Web Application in GDI+ using VB.NET
Working with Text and Strings in VB.NET
GDI+ Transforming Text in VB.NET
GDI+ LinearGradientBrush and PathGradientBrush in VB.NET
Drawing GDI+ Images on the Web in VB.NET
Drawing Simple Graphics in VB.NET
Graphics Web Application in GDI+ usnig VB.NET
Adding GDI+ Web Controls to a Web Form in VB.NET
Customizing Page Settings in GDI+ using VB.NET
DetailsCustom Controlling and Print Controller in VB.NET
Drawing Graphics Shapes in VB.NET
The DocumentName Property and Marginal Printing in VB.NET
Draw 2D graphics line,tringle,ellipse,polygon in VB.NET
Print Dialogs in GDI+ using VB.NET
Printing Graphics in GDI+ using VB.NET
Printing Text in GDI+ using VB.NET
A GDI+ Printer Settings Example in VB.NET
GDI+ Pinting Application in VB.NET
Printer Settings in GDI+ using VB.NET
GDI+ PaperSize Class in VB.NET
Printing in GDI+ using VB.NET
GDI+ Text Transformation in VB.NET
Color Transformation and the Color Matrix in VB.NET
Image Transformation in GDI+ using VB.NET
GDI+ Scaling, Shearing and Rotating Colors in VB.NET
GDI+ Miscellaneous Advanced 2D Topics in VB.NET
Mixed Blending in GDI+ using VB.Net
Compositing Mode and Blending in VB.NET
© 2020 DotNetHeaven. All rights reserved.
TERMS & CONDITIONS
|
CONTACT US
|
REPORT ABUSE