从png图像导出蒙板,从蒙板拼合图像
来源:互联网 发布:php互助金融 编辑:程序博客网 时间:2024/05/16 04:37
//======================================================= //获取图像pic的遮罩图像 //======================================================= //将png透明图像,转化为一张不含透明度的jpeg图像 和 一张仅含透明度的png图像 public Bitmap[] getPicMask(Image pic) { Bitmap[] tmp = new Bitmap[2]; tmp[0] = ToBitmap(pic); tmp[1] = ToBitmap(pic); tmp[0] = getRGB(tmp[0]); //获取除透明度信息外的图像 tmp[1] = getAlpha(tmp[1]); //获取图像的透明度图像 return tmp; } //获取图像对应的RGB图像,透明度数据清除 public Bitmap getRGB(Bitmap pic) { Color C; for (int i = 0; i < pic.Height; i++) { for (int j = 0; j < pic.Width; j++) { C = pic.GetPixel(j, i); C = Color.FromArgb(0, C.R, C.G, C.B); //清除透明度信息 pic.SetPixel(j, i, C); } } return pic; } //获取图像的遮罩图像,仅保留透明度信息 public Bitmap getAlpha(Bitmap pic) { Color C; for (int i = 0; i < pic.Height; i++) { for (int j = 0; j < pic.Width; j++) { C = pic.GetPixel(j, i); C = Color.FromArgb(0, C.A, C.A, C.A); //使用透明度信息生成遮罩图像 pic.SetPixel(j, i, C); } } return pic; }
//======================================================= //为图像pic的添加遮罩图像 //======================================================= public Bitmap setPicMask(Image Pic, Image Mask) { if (Pic == null) return null; Bitmap pic = ToBitmap(Pic); if (Mask == null) return pic; Bitmap mask = ToBitmap(Mask); if(pic.Width != mask.Width || pic.Height != mask.Height) return pic; Color C, C2; for (int i = 0; i < pic.Height; i++) { for (int j = 0; j < pic.Width; j++) { C = pic.GetPixel(j, i); //读取原图像的RGB值 C2 = mask.GetPixel(j, i); //读取蒙板的透明度信息 //if (C2.R == 0) C = Color.FromArgb(0, 0, 0, 0); // Color.Empty; if (C2.R == 0) C = Color.Transparent; else C = Color.FromArgb(C2.R, C.R, C.G, C.B); //清除透明度信息 pic.SetPixel(j, i, C); } } return pic; }
//Image转化为Bitamap public Bitmap ToBitmap(Image pic) { //创建图像 Bitmap tmp = new Bitmap(pic.Width, pic.Height); //按指定大小创建位图 Rectangle Rect = new Rectangle(0, 0, pic.Width, pic.Height); //pic的整个区域 //绘制 Graphics g = Graphics.FromImage(tmp); //从位图创建Graphics对象 g.Clear(Color.FromArgb(0, 0, 0, 0)); //清空 g.DrawImage(pic, Rect, Rect, GraphicsUnit.Pixel); //从pic的给定区域进行绘制 return tmp; //返回构建的新图像 }
0 0
- 从png图像导出蒙板,从蒙板拼合图像
- 从图像提交表单
- 从URL加载图像
- 从一图像中截取部分图像
- 从图像处理到图像识别
- 图像拼合中的渐晕校正模型
- 从数据库中读取图像
- 图像(从网上收集整理)
- 从缓存中读取图像
- 从梯度场重建图像
- opencv 从内存加载图像
- 抠图:从分析图像入手
- 图像处理,从现在开始。
- PNG图像压缩
- PNG图像(一)
- 分析PNG图像结构
- LIBPNG读写PNG图像
- LIBPNG显示PNG图像
- 程序员需要研究厚黑学吗
- 二叉树的C++实现
- 聊天服务
- 将pdf转换成ppt的简易教程
- Hibernate 参数设置一览表
- 从png图像导出蒙板,从蒙板拼合图像
- Nginx Gzip 压缩配置
- python pep8编码规范
- scala实现设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1
- Java 内存区域和GC机制
- memset
- 利用远程线程进行DLL的注入
- 正则表达式语法
- OC内存管理