• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
wjshan0808

Learn from yesterday, Live for today, For a better tomorrow.
 ————wjshan0808

博客园    首页    新随笔    联系   管理    订阅  订阅

光照效果

private const float BRIGHTNESS = 220.0F;
Graphics g = this.pictureBox2.CreateGraphics(); g.Clear(Color.White); Bitmap bmp = new Bitmap(this.pictureBox1.Image); int width = bmp.Width; int height = bmp.Height; Bitmap tmp = bmp.Clone(new RectangleF(0, 0, width, height), System.Drawing.Imaging.PixelFormat.DontCare); //发亮点右上角 此值会让强光中心发生偏移 Point lightP = new Point(width - 40, height / 4); //R强光照射面的半径,即”光晕” int radius = Math.Min(width / 2 + 60, height / 2 + 60); for (int i = 1; i < width; i++) for (int j = 1; j < height; j++) { float length = (float)Math.Sqrt(Math.Pow((i - lightP.X), 2) + Math.Pow((j - lightP.Y), 2)); //如果像素位于”光晕”之内 if (length < radius) { Color C = tmp.GetPixel(i, j); int rV, gV, bV; //亮度增加常量,该值越大,光亮度越强 float pixel = BRIGHTNESS * (1.0f - (length / radius)); rV = C.R + (int)pixel; rV = Math.Max(0, Math.Min(rV, 255)); gV = C.G + (int)pixel; gV = Math.Max(0, Math.Min(gV, 255)); bV = C.B + (int)pixel; bV = Math.Max(0, Math.Min(bV, 255)); //将增亮后的像素值回写到位图 Color newC = Color.FromArgb(255, rV, gV, bV); tmp.SetPixel(i, j, newC); } } g.DrawImage(tmp, pictureBox2.ClientRectangle);// new Rectangle(0, 0, width, height));
       g.Dispose();


posted @ 2015-01-22 09:55  wjshan0808  阅读(149)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3