/// <Summary> /// Generate a watermark. You can generate a file based on the top left, bottom left, top right, bottom right, center, and transparency. It is only valid for jpeg or jpg format! /// </Summary> /// <Param name = "sourceFile"> basemap </param> /// <Param name = "waterMarkFile"> watermark image </param> /// <Param name = "saveFile"> file to be saved </param> /// <Param name = "local"> position: Top left (1), bottom left (2), top right (3), bottom right (4), center (5) </param> /// <Param name = "alpha"> Transparency (1-100) </param> /// <Returns> bool, whether it is successful </returns> Public static bool MakeWaterImage (string sourceFile, string waterMarkFile, string saveFile, int local, int alpha) { Bool result; If (! File. Exists (sourceFile) |! File. Exists (waterMarkFile) // if the source image or watermark image does not exist Return false; FileInfo fi = new FileInfo (sourceFile ); // Determine whether the file type is valid If (fi. Extension. ToLower ()! = ". Jpg" & fi. Extension. ToLower ()! = ". Jpeg ") Return false; Try { // Source Image Bitmap sImage = new Bitmap (sourceFile ); Int sWidth = sImage. Width; Int sHeight = sImage. Height; // Watermark image Bitmap wImage = new Bitmap (waterMarkFile ); Int wWidth = wImage. Width; Int wHeight = wImage. Height;// Make Graphics. Graphics g = Graphics. FromImage (sImage ); Int x; // Temporary Variable Int y; // monitoring variable Int x1 = 0; // The width difference between the source image and the watermark image, that is, the X position of the start drawing. Int y1 = 0; // the height difference between the source image and the watermark image, that is, the Y position of the Start plot. Int w = 0; // The width of the watermark image generated, that is, the X position of the ending drawing. Int h = 0; // The height of the watermark image generated, that is, the Y position of the ending plot. Int al; // alpha Int rl; // Red Int gl; // Green Int bl; // Blue // Verify transparency If (alpha <1 || alpha> 100) Al = 80; Else Al = alpha; If (sWidth> wWidth & sHeight> wHeight) // if the source image is larger than the watermark image { Switch (local) { Case 1: // top left X1 = 0; Y1 = 0; |