C# GDI+ Programming (3)
Color’s Alpha value
Color can also set the Alpha value, which is the transparency. Such as Color.FromArgb(120,255,255,255). FromArgb has four parameters, the first one specifies the Alpha value.
The last three are color values RGB.
The alpha value range is 0~255, 0 means completely transparent, and 255 means opaque.
Look at an example of a semi-transparent brush:
using use using use using using through use through out ’s ’ s through out using off ‐ ‐ ‐‐‐‐‐ and
to be a semi-transparent brush.
Rectangle rect = new Rectangle(0, 0, 100 , 100); Path.AddRectangle(rect);径 // Create road drawing brush
PATHGRADIENTBRUSH BRUSH = New Pathgradientbrush (PATH);
// central point color
brush.centercolor = color.fromargb (120,255,255); ) The color on the upper u Brush.Surroundcolors = new Color[] { Color.FromArgb(120,0,0,0)};
If the color of the brush If the Alpha (transparent) value is not set, the displayed string cannot be seen.
Anti-aliasing
Eliminating the aliasing of lines is accomplished by setting the SmoothingMode attribute member in the Graphics class, which is an enumeration type.
Example statement to set anti-aliasing: e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
After eliminating aliasing, the lines look much smoother.
//Eliminate aliasing
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;using use use with using using through using ’ ’ s ’ through using ’s way through ’ through ‐ to ‐‐ ‐‐‐ , � ;
e.Graphics.DrawEllipse(pen, rect2) ;The SmoothingMode enumeration also has some other members, which can set different levels of anti-aliasing or not.
Text anti-aliasing
To anti-alias the displayed text, just set TextRenderingHint.
Sample code:
private void formPaint(Object sender, PaintEventArgs e)
ing("ABCDEFGHIJKL", new Font("宋体", 15f), brush, 0, 20);
new Font("宋体", 15f), brush, 0, 50);
}
area
It’s best to understand these functions, because C# can also call these APIs. And many of the concepts there are similar. For example, window handle, area handle.
For example, the GetHrgn function in the Region class can get the region handle.
Also let’s talk about the relationship between area and path, so that you can better understand what the area is. The relationship between area and path is like the relationship between filled graphics and graphics.
You can use paths and rectangles to create a area. Through the Region's constructor.
The following example creates two areas with rectangles and fills them. V Private void Formpaaint on2 = New Region (New Rectangle (50,50,100,100));
Graphics.Fillregion (brush1, region1);// Create a painting brush 2, and fill the area 2
solidbrush brush2 = new solidbrush (color.fromargb (125, 0, 255));E. Graphics. FillRegion (brush2 , region2);
}
In addition, two regions can also be merged. Merging regions has also been discussed in the 95th function CombineRgn. You can refer to that function.
CombineRgn The last parameter nCombineMode of the API function specifies how to merge two regions, so the merge in the Region class should also have a similar function.
Indicate how to merge, but the Region class is not specified with parameters. Region directly calls different functions.
For example, the Region.Intersect function is RGN_AND, and Region.Union is the RGN_OR method of merging. . region1.Exclude is RGN_DIFF,
Region. ;>>>>>>>>>>>>>>>>>From API CombineRgn function>>>>>> ;>>>>>>>>>>>>>>>>>>>>>>>>> ;>>>>>>>>>>>>>>>>>>>
RGN_AND The overlapping portion of the two regions
RGN_OR Combine two regions
RGN_DIFF The non-overlapping part of hSrcRgn1
RGN_XOR The non-overlapping part of hSrcRgn1 and hSrcRgn2
<<<<<<<<<<<<<<<<<<<<<<<< ;<<<<<<<<<<<<<<<<<<<<<<<< ;<<<<<<<<<<<<<<<<<<<<<<<< ;<<<<<<<<<<<<<<<<<<<<<<<< ;<<<
There is also a function Complement in the Region class. The area obtained by merging with this function is the non-overlapping part of area 2.
Look at the example:
private void formPaint(Object sender, PaintEventArgs e)
0,0,100,100));
Region region2 = New Region (New Rectangle (50,50,100,100));
// Use the XOR function merging area to obtain the unpacking parts of the two areas.
region1.
}
Settings window Display area:
Just specify the Region attribute member in the Form class, for example, display a circular window:
InitializeComponent(); // Create a circular path
GraphicsPath path = new GraphicsPath ( );this.Region = region;
Region.IsVisible determines whether a point (or rectangle) is within the region.
Look at the example. In the example, a circular area is created. As soon as the mouse enters the circular area, the area will display red. P PARIC PARTIAL CLASS FORM1: Form
{
// Public Solidbrush Norbrush = New Solidbrush (COLOR.GREEN); c solidBrush Hovbrush = New solidbrush (color.red);
// indicate whether the mouse is in the region
public Bool Hovflag = False; ecomponent ();
// Create a circular path
GraphicsPath path = new using using using using using using using ‐ through through through off ‐ through ’ ‐ ‐ ‐‐ ‐‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ to new Region(path);
件 // Add event processing
This.paint+= Formpaaint;
// Mouse Mobile Event
This.Mousemove+= Frommousemove;
}}
targs e)
{
if (hovflag)
{
e.Graphics.FillRegion(hovBrush, region); . gion(norBrush, region);
gion; , MouseEventArgs e)
Graphics Graphics . hovFlag != true)
hovFlag . FillRegion (HOVBRUSH, Region);
}
// The mouse leaves the area
else if (region.isvisible (e.x, e.y)! = True && Hovflag) {
hovflag = false;
.FillRegion (norbrush, region) ;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article explains how to create newline characters in C using the \n escape sequence within printf and puts functions. It details the functionality and provides code examples demonstrating its use for line breaks in output.

This article explores the challenges of NULL pointer dereferences in C. It argues that the problem isn't NULL itself, but its misuse. The article details best practices for preventing dereferences, including pre-dereference checks, pointer initiali

This article guides beginners on choosing a C compiler. It argues that GCC, due to its ease of use, wide availability, and extensive resources, is best for beginners. However, it also compares GCC, Clang, MSVC, and TCC, highlighting their differenc

This article emphasizes the continued importance of NULL in modern C programming. Despite advancements, NULL remains crucial for explicit pointer management, preventing segmentation faults by marking the absence of a valid memory address. Best prac

This article reviews online C compilers for beginners, focusing on ease of use and debugging capabilities. OnlineGDB and Repl.it are highlighted for their user-friendly interfaces and helpful debugging tools. Other options like Programiz and Compil

This article discusses efficient code copying in C IDEs. It emphasizes that copying is an IDE function, not a compiler feature, and details strategies for improved efficiency, including using IDE selection tools, code folding, search/replace, templa

This article compares online C programming platforms, highlighting differences in features like debugging tools, IDE functionality, standard compliance, and memory/execution limits. It argues that the "best" platform depends on user needs,

This tutorial guides users through installing C compilers on Windows, macOS, and Linux. It details installation for popular compilers (MinGW, Visual Studio, Xcode, GCC), explains environment variable configuration, and offers troubleshooting steps
