国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現繪制浮雕圖片效果實例

2020-01-24 02:33:45
字體:
來源:轉載
供稿:網友

本文采用C#實例講解了處理圖片為浮雕效果的實現方法,這在PS中是一個常見的功能,也是C#中的一個簡單的圖像處理例子。程序先讀取原圖,然后依次訪問每個像素的RGB值,獲取相鄰兩個像素的R、G、B值,計算與左上角像素的RGB分量之差,將計算后的RGB值回寫到位圖,最后進行圖片的浮雕處理。

主要代碼如下:

using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Drawing.Imaging;namespace EmbossColander{ public class Form1 : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; public Form1() {  InitializeComponent(); } protected override void Dispose( bool disposing ) {  if( disposing )  {  if (components != null)  {   components.Dispose();  }  }  base.Dispose( disposing ); } #region Windows 窗體設計器生成的代碼 private void InitializeComponent() {  this.components = new System.ComponentModel.Container();  this.Size = new System.Drawing.Size(350,200);  this.Text = "Form1"; } #endregion protected override void OnPaint(PaintEventArgs e) {  base.OnPaint (e);  Graphics graphics = e.Graphics;  graphics.Clear(Color.White);  graphics.ScaleTransform(0.7f,0.7f);  Bitmap image = new Bitmap("dog.bmp");  int Width = image.Width;  int Height = image.Height;  //image2:進行雕刻處理  Bitmap image2 = image.Clone(new Rectangle(0,0,Width,Height),PixelFormat.DontCare );  //繪制原圖  graphics.DrawImage(  image, new Rectangle(0, 0, Width, Height));  Color color, colorTemp,colorLeft;  //進行圖片的浮雕處理  //依次訪問每個像素的RGB值  for(int i=Width-1; i>0;i--)  {  for( int j=Height-1; j>0;j--)  {   //獲取相鄰兩個像素的R、G、B值   color =image.GetPixel(i, j);   colorLeft=image.GetPixel(i-1, j-1);   //計算與左上角像素的RGB分量之差   //67:控制圖片的最低灰度,128:常量,更改這兩個值會得到不同的效果   int r = Math.Max(67,Math.Min(255,   Math.Abs(color.R-colorLeft.R+128)));   int g = Math.Max(67,Math.Min(255,   Math.Abs(color.G-colorLeft.G+128)));   int b = Math.Max(67,Math.Min(255,   Math.Abs(color.B-colorLeft.B+128)));   Color colorResult=Color.FromArgb(255,r,g,b);   //將計算后的RGB值回寫到位圖   image.SetPixel(i, j,colorResult);  }  //繪制浮雕圖  graphics.DrawImage(   image, new Rectangle(Width+10, 0, Width, Height));  } } [STAThread] static void Main() {  Application.Run(new Form1()); } }}

感興趣的朋友可以點此本站下載完整實例代碼。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 定西市| 佳木斯市| 井陉县| 乐亭县| 葵青区| 资兴市| 长春市| 襄樊市| 达州市| 平江县| 安顺市| 玉屏| 新民市| 邹平县| 浦城县| 慈溪市| 盐城市| 克山县| 高雄县| 从江县| 宣化县| 鲁山县| 旅游| 无为县| 志丹县| 江北区| 彭阳县| 潼关县| 新和县| 平泉县| 隆子县| 文水县| 泰顺县| 鄂温| 金昌市| 鄂托克前旗| 辽阳市| 松阳县| 松阳县| 栾城县| 吴忠市|