Gephi’s simple drawing learns to learn together

2023-01-24   ES  

front -end code:

<body> 
     <FORM METHOD = "Post" Action = "ProcessFileup.ASHX" Enctype = "Multipart/Form-Data">> 
         <input type = "file" name = "fileup" /> 
         <input type = "submit" value = "upload" /> 
     </form> 
 </body>

Basic drawing:

back -end code analysis:

0. Set quotation:

using System.Drawing;

1. Create a canvas

// Create a canvas 
 using (bitmap map = new bitmap (300,400))

2. Create a brush

// Create a brush for the canvas 
 using (Graphics G = Graphics.fromimage (MAP))

3. Clear the canvas and fill in the specified color (equivalent to initialized canvas)

// Clear the canvas and fill in the specified color 
 g.clear (color.white);

4. There are many methods on the canvas (there are many methods, such as drawing graphics, writing, etc. This example provides writing operations)

// 1. What words write 
 // 2. Font style 
 // 3. What color fills font 
 // 4. Where to write in the canvas 
 G.Drawstring ("Wryyyyyyyy!", New FONT ("Black Body", 14.0F, FontStyle.regular), Brushes.orange, New Pointf (150, 200));

5. Save the canvas into a picture and specify the picture type

// Rename the file 
 string filename = guid.newguid (). Tostring (); 
 // Save the canvas into a picture and specify the picture type 
 map.save (context.request.mappath ("/imageupload/" + filename + ". JPG"), System.Drawing.imaging.imageFormat.jpeg); 
 Context.Response.write (<hTML> <body> <IMG SRC = '/Imageupload/" + FILENAME +" .jpg'/Body> </html> ");););

Results:

Full code:

USING SYSTEM; 
 using system.collections.gneric; 
 using system.linq; 
 using system.web; 
 using system.drawing; 

 namespace webapp 
 {{ 
     /// <summary> 
     /// MakeImage Abstract 
     /// </summary> 
     public class makeImage: IHTTPHANDLER 
     {{ 

         Public Void ProcessRequest (HTTPCONTEXTEXT Context) 
         {{ 
             context.Response.contentType = "Text/HTML"; 
             // Create a picture for users and save 
             // Create a canvas 
             using (bitmap map = new bitmap (300,400)) 
             {{ 
                 // Create a brush to the canvas 
                 using (Graphics G = Graphics.fromimage (MAP)) 
                 {{ 
                     // Clear the canvas and fill in the specified color 
                     g.clear (color.white); 
                     // 1. What words write 
                     // 2. Font style 
                     // 3. What color fills font 
                     // 4. Where to write in the canvas 
                     G.Drawstring ("Wryyyyyyyy!", New FONT ("Black Body", 14.0F, FontStyle.regular), Brushes.orange, New Pointf (150, 200)); 

                     // Rename the file 
                     string filename = guid.newguid (). Tostring (); 
                     // Save the canvas into a picture and specify the picture type 
                     map.save (context.request.mappath ("/imageupload/" + filename + ". JPG"), System.Drawing.imaging.imageFormat.jpeg); 
                     Context.Response.write (<hTML> <body> <IMG SRC = '/Imageupload/" + FILENAME +" .jpg'/Body> </html> "););); 
                 } 
             } 
         } 

         Public Bool Isreusable 
         {{ 
             get 
             {{ 
                 Return false; 
             } 
         } 
     } 
 }

Add watermark to the picture:

In fact, the operation and drawing are almost the same, but the drawing is placed on a canvas, and the watermark is to put the picture for the picture, which means that the picture is used as a canvas here.

1. Get the picture, there are two ways:

Get according to the picture file stream:

Useing (Image Img = Image.fromStream (File.inputStream)) // Obtain the picture according to the file stream data of the picture

According to the physical path of the picture:

Useing (Image Img = Image.fromfile (context.request.mappath (fultir))) //

2. Create a canvas, but since the canvas are used as a picture, the size of the canvas must be consistent with the picture:

USING

3. Create a brush for the canvas:

Useing (Graphics g = Graphics.fromimage (MAP)) // Create a brush for the canvas

4. Now I just created an empty canvas. This step needs to “draw” the picture on the canvas:

g.DrawImage (img, 0,0, img.width, img.head); // Use a brush to draw pictures on the canvas, draw the entire picture on the upper left corner of the canvas to the canvas on the canvas on the canvas on the canvas

5. Watermark, save pictures, show the picture:

g.DrawImage (img, 0,0, img.width, img.head); // Use a brush to draw pictures on the canvas, draw the entire picture on the upper left corner of the canvas to the canvas on the canvas on the canvas on the canvas 
 G.Drawstring ("KO No DIO DA!", New FONT ("Black Body", 14.0F, FONTSTYLE.Regular), Brushes.orange, New Pointf (Map.width-100, Map.head-25)); // Add words on the picture 
 string waterImageName = "Water_" + GUID.Newguid (). Tostring (); 
 Map.save (context.request.mappath ("/imageupload/" +wateragename +". JPG"), system.drawing.imaging.imageformat.jpeg); 
 Context.Response.write ("<html> <body> <IMG SRC = '/Imageupload/" + WaterimageName + ".jpg'/> </html>" "); // Fulldir contains the current folder Therefore, no need to add before

source

Related Posts

Direct directory and files in the directory in the shape of this directory

UVA122 Question Report Aleks

JS SLICE, SUBSTRING and SUBSTR differences zhongjian

Use John to blast the password

Gephi’s simple drawing learns to learn together

Random Posts

java network programming (9) -How do netty do data communication? How to achieve Netty heartbeat detection? How to communicate with http protocols? Levi

Git entry and basic operations

[Linux User Space Programming-3]: Several implementation methods of Linux timing mechanism

GO and Java how to handle the concurrent and intersection of the two arrays

Netty Implementing HTTP server