search
C# GDI+ Programming (3)Dec 17, 2016 am 10:14 AM

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.

The corresponding code is:

                                                                                                                                                                                                                                                                                  lipse(pen, rect1);

//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:

       public Form1()

                                  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) ;
                                                                                                                                                                   ​ 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to use char array in C languageHow to use char array in C languageApr 03, 2025 pm 03:24 PM

The char array stores character sequences in C language and is declared as char array_name[size]. The access element is passed through the subscript operator, and the element ends with the null terminator '\0', which represents the end point of the string. The C language provides a variety of string manipulation functions, such as strlen(), strcpy(), strcat() and strcmp().

What is the role of char in C stringsWhat is the role of char in C stringsApr 03, 2025 pm 03:15 PM

In C, the char type is used in strings: 1. Store a single character; 2. Use an array to represent a string and end with a null terminator; 3. Operate through a string operation function; 4. Read or output a string from the keyboard.

How to handle special characters in C languageHow to handle special characters in C languageApr 03, 2025 pm 03:18 PM

In C language, special characters are processed through escape sequences, such as: \n represents line breaks. \t means tab character. Use escape sequences or character constants to represent special characters, such as char c = '\n'. Note that the backslash needs to be escaped twice. Different platforms and compilers may have different escape sequences, please consult the documentation.

How to use various symbols in C languageHow to use various symbols in C languageApr 03, 2025 pm 04:48 PM

The usage methods of symbols in C language cover arithmetic, assignment, conditions, logic, bit operators, etc. Arithmetic operators are used for basic mathematical operations, assignment operators are used for assignment and addition, subtraction, multiplication and division assignment, condition operators are used for different operations according to conditions, logical operators are used for logical operations, bit operators are used for bit-level operations, and special constants are used to represent null pointers, end-of-file markers, and non-numeric values.

The difference between multithreading and asynchronous c#The difference between multithreading and asynchronous c#Apr 03, 2025 pm 02:57 PM

The difference between multithreading and asynchronous is that multithreading executes multiple threads at the same time, while asynchronously performs operations without blocking the current thread. Multithreading is used for compute-intensive tasks, while asynchronously is used for user interaction. The advantage of multi-threading is to improve computing performance, while the advantage of asynchronous is to not block UI threads. Choosing multithreading or asynchronous depends on the nature of the task: Computation-intensive tasks use multithreading, tasks that interact with external resources and need to keep UI responsiveness use asynchronous.

How to convert char in C languageHow to convert char in C languageApr 03, 2025 pm 03:21 PM

In C language, char type conversion can be directly converted to another type by: casting: using casting characters. Automatic type conversion: When one type of data can accommodate another type of value, the compiler automatically converts it.

What is the function of C language sum?What is the function of C language sum?Apr 03, 2025 pm 02:21 PM

There is no built-in sum function in C language, so it needs to be written by yourself. Sum can be achieved by traversing the array and accumulating elements: Loop version: Sum is calculated using for loop and array length. Pointer version: Use pointers to point to array elements, and efficient summing is achieved through self-increment pointers. Dynamically allocate array version: Dynamically allocate arrays and manage memory yourself, ensuring that allocated memory is freed to prevent memory leaks.

Avoid errors caused by default in C switch statementsAvoid errors caused by default in C switch statementsApr 03, 2025 pm 03:45 PM

A strategy to avoid errors caused by default in C switch statements: use enums instead of constants, limiting the value of the case statement to a valid member of the enum. Use fallthrough in the last case statement to let the program continue to execute the following code. For switch statements without fallthrough, always add a default statement for error handling or provide default behavior.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool