簡單文字圖片浮水印效果 - C#WinForm

來源:互聯網
上載者:User

 

 

 


對應代碼下載:http://download.csdn.net/source/1210790

  //原始圖片 public void originalImage() { String sourcePath = @"../../Resources/test.jpg"; System.Drawing.Image image = System.Drawing.Image.FromFile(sourcePath); resultImage.Image = image; } //加文字浮水印 public void makeWordWatermark() { String sourcePath = @"../../Resources/test.jpg"; System.Drawing.Image image = System.Drawing.Image.FromFile(sourcePath); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image); graphics.DrawImage(image, 0, 0, image.Width, image.Height); System.Drawing.Font font = new System.Drawing.Font("Verdana", 30); System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.White); string addText = "圖片添加文字浮水印效果"; graphics.DrawString(addText, font, brush, 10, 10); graphics.Dispose(); resultImage.Image = image; } //圖片整體設定透明度 public void makeImageWatermark() { String sourcePath = @"../../Resources/test.jpg"; String copyPath = @"../../Resources/image.jpg"; System.Drawing.Image image = System.Drawing.Image.FromFile(sourcePath); System.Drawing.Image copyImage = System.Drawing.Image.FromFile(copyPath); Graphics g = Graphics.FromImage(image); //透明度設定 float alpha = 0.15f; //ImageAttributes 對象包含有關在呈現時如何操作位元影像和圖元檔案顏色的資訊。 ImageAttributes imageAttributes = new ImageAttributes(); //Colormap: 定義轉換顏色的映射 ColorMap colorMap = new ColorMap(); //此處浮水印圖被定義成擁有綠色背景色的圖片被替換成透明 colorMap.OldColor = Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap); float[][] colorMatrixElements = { new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // red紅色 new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, //green綠色 new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, //blue藍色 new float[] {0.0f, 0.0f, 0.0f, alpha, 0.0f}, //透明度 new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}}; // ColorMatrix:定義包含 RGBA 空間座標的 5 x 5 矩陣。 // ImageAttributes 類的若干方法通過使用顏色矩陣調整映像顏色。 ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); g.DrawImage(copyImage, new Rectangle(image.Width - copyImage.Width, image.Height - copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel, imageAttributes); g.Dispose(); resultImage.Image = image; }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.