使透明
大家好,小范来为大家解答以上的问题。使透明这个很多人还不知道,现在让我们一起来看看吧!
1、正好软糖做过这个软件^o^,切割图片并保存一堆小图片到FileName-###.png效果图软糖切图 - 核心代码using System;using System.Drawing;using System.Drawing.Imaging;using System.Drawing.Drawing2D;using System.IO;namespace 软糖切图{ public class 网格精灵 { public string 文件地址; public string 输出目录; public string 输出后缀名 = @".png"; public static string 命名格式 = @"{0}_{1}_{2}"; public Bitmap 原始; public Bitmap 当前; public ImageFormat 图像格式; public Graphics 画板; public Color 透明色; public Pen 网格画笔 = new Pen(Color.FromArgb(255, 255, 0, 255), 2); public Color 无效区域色 = Color.White; public Brush 背景画刷 = new HatchBrush(HatchStyle.LightDownwardDiagonal, Color.White,Color.LightGray); public int OX = 0; public int OY = 0; public int W; public int H; public int iX; public int iY; public bool 显示网格 = true; public void 打开(string 文件地址) { 装载位图( new Bitmap(文件地址)); } public void 装载位图(Bitmap 位图) { 原始 = 位图; 图像格式 = ImageFormat.Png; 自动调整网格(); 当前 = new Bitmap(原始, 原始.Size); 画板 = Graphics.FromImage(当前); } public void 重新装载() { 当前 = new Bitmap(原始, 原始.Size); 画板 = Graphics.FromImage(当前); } public void 重新绘制() { if (原始 == null) { return; } 绘制位图(画板); 绘制网格(画板); } public void 调整网格线宽度(float 宽度) { if (宽度 <= 0) { 显示网格 = false; } else { 显示网格 = true; } 网格画笔.Width = 宽度; 重新绘制(); } private void 自动调整网格() { if (原始.Width < W) { W = 原始.Width; } if (原始.Height < H) { H = 原始.Height; } //计算格子数量 iX = (int)((原始.Width - OX) / W); iY = (int)((原始.Height - OY) / H); } private void 绘制位图(Graphics v画板) { v画板.Clear(无效区域色); if (当前 == null) { return; } Rectangle RECT = new Rectangle(0, 0, 当前.Width, 当前.Height); v画板.FillRectangle(背景画刷, RECT); v画板.DrawImage(原始, RECT); } private void 绘制网格(Graphics v画板) { //检查位图和格子宽高 if (当前 == null) { return; } if (显示网格 == false) { return; } if (W <= 0) { W = 32; } if (H <= 0) { H = 32; } //计算格子数量 iX = (int)((当前.Width - OX) / W); iY = (int)((当前.Height - OY) / H); //检查格子数量 if (iX < 1) { return; } if (iY < 1) { return; } //绘制网格线 int x1, x2, y1, y2; for (int x = 1; x <= iX + 1; x++) { x1 = (x - 1) * W - OX; y1 = 0; x2 = x1; y2 = 当前.Height; v画板.DrawLine(网格画笔, x1, y1, x2, y2); } for (int y = 1; y <= iY + 1; y++) { x1 = 0; y1 = (y - 1) * H - OY; x2 = 当前.Width; y2 = y1; v画板.DrawLine(网格画笔, x1, y1, x2, y2); } } public Color 取色(int x,int y) { if (当前 == null){ return Color.Black; } return 当前.GetPixel(x, y); } public void 开关透明(bool 透明) { if (当前 == null) { return; } //重新装载(); if (透明) { 当前.MakeTransparent(透明色); } 重新绘制(); } public void 裁剪() { //检查位图和格子宽高 if (当前 == null) { return; } if (W <= 0) { W = 32; } if (H <= 0) { H = 32; } //计算格子数量 iX = (int)((当前.Width - OX) / W); iY = (int)((当前.Height - OY) / H); //检查格子数量 if (iX <= 1) { return; } if (iY <= 1) { return; } //剪辑位图并保存 for (int y = 1; y <= iY; y++) { for (int x = 1; x <= iX; x++) { int i = x + (y - 1) * iX; Rectangle 源矩形 = new Rectangle( (x - 1) * W - OX, (y - 1) * H - OY, W, H); Rectangle 目标矩形 = new Rectangle(0, 0, W, H); Bitmap t剪辑 = new Bitmap(W, H, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(t剪辑); g.DrawImage(当前, 目标矩形, 源矩形, GraphicsUnit.Pixel); g.Dispose(); string 路径 = Path.Combine(输出目录, 获取文件名(i) + 获取后缀名()); t剪辑.Save(路径, 图像格式); } } } private string 获取文件名(int ID) { string 文件名 = System.IO.Path.GetFileNameWithoutExtension(文件地址); string strID = ID.ToString(); string strDate = DateTime.Now.ToString("yyyyMMdd"); return string.Format(命名格式, 文件名, strID, strDate); } private string 获取后缀名() { return 输出后缀名; } }}调用方法精灵.打开(文件地址);精灵.W = 32; //每个分割方块的宽度精灵.H = 32; //每个分割方块的高度//精灵.透明色 = Color.FromArgb(255,255,255); //需要透明色就删掉注释//精灵.开关透明 = true;精灵.输出目录 = @"D:Out";精灵.裁剪();比如你的图片是50*50的,要分割成4张25*25的首先初始化4张bitmap。
2、然后遍历50*50的bitmap,利用Getpixel获取像素点,然后Setpixel给25*25的图片。
本文到此分享完毕,希望对大家有所帮助。
免责声明:本文由用户上传,与本网站立场无关。财经信息仅供读者参考,并不构成投资建议。投资者据此操作,风险自担。 如有侵权请联系删除!
-
【盘点关于创新的四字词语】在当今快速发展的社会中,创新已成为推动进步的重要动力。无论是企业、科研机构还...浏览全文>>
-
【盘点关于除夕的古诗词】除夕,作为中国农历年的最后一天,承载着丰富的文化内涵和情感寄托。自古以来,文人...浏览全文>>
-
【盘点公寓房和商品房的区别】在购房过程中,很多人会对“公寓房”和“商品房”这两个概念感到困惑。其实,这...浏览全文>>
-
【盘点跟兔子有关的网名】在如今的网络世界中,越来越多的人喜欢用一些可爱、有趣的网名来表达自己的个性或兴...浏览全文>>
-
【盘点跟手有关的成语】在汉语中,许多成语都与“手”这个字密切相关,它们不仅生动形象地描绘了人的动作或状...浏览全文>>
-
【盘点高中开学必备物品清单】随着新学期的临近,很多高中生和家长都在为开学做准备。为了帮助大家更高效地整...浏览全文>>
-
【盘点高考注意事项】高考是每个学生人生中的一次重要考试,关系到未来的发展方向。为了帮助考生在考试中发挥...浏览全文>>
-
【盘点高层顶楼最贵的原因】在房地产市场中,高层住宅的顶楼往往价格较高,许多购房者对此感到疑惑:为什么顶...浏览全文>>
-
【盘点非洲人与动物的纪录片】非洲,这片充满神秘与生机的土地,不仅是人类文明的摇篮,也是无数野生动物的家...浏览全文>>
-
【排骨炖玉米煮多少时间】在日常生活中,排骨炖玉米是一道非常受欢迎的家常菜,既营养丰富又味道鲜美。很多人...浏览全文>>