Bitmap添加水印提示【无法从带有索引像素格式的图像创建Graphics对象】
来源:互联网 发布:young网络下载 编辑:程序博客网 时间:2024/05/22 14:06
给图片添加水印时
Bitmap img = bm.ToBitmap();
Graphics g1 = Graphics.FromImage(img);
调用上面的语句,出现这个错误提示:
Bitmap img = bm.ToBitmap(); //如果原图片是索引像素格式之列的,则需要转换 if (IsPixelFormatIndexed(img.PixelFormat)) { Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmp); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.DrawImage(img, 0, 0); //加水印 String str = "hello, string"; Font font = new Font("宋体", 8); SolidBrush sbrush = new SolidBrush(Color.Black); g.DrawString(str, font, sbrush, new PointF(10, 10)); pictureBox1.Image = bmp; } else { //直接加水印 }
添加引用和函数
using System.Drawing.Imaging; /// <summary> /// 会产生graphics异常的PixelFormat /// </summary> private static PixelFormat[] indexedPixelFormats = { PixelFormat.Undefined, PixelFormat.DontCare, PixelFormat.Format16bppArgb1555, PixelFormat.Format1bppIndexed, PixelFormat.Format4bppIndexed, PixelFormat.Format8bppIndexed }; /// <summary> /// 判断图片的PixelFormat 是否在 引发异常的 PixelFormat 之中 /// </summary> /// <param name="imgPixelFormat">原图片的PixelFormat</param> /// <returns></returns> private static bool IsPixelFormatIndexed(PixelFormat imgPixelFormat) { foreach (PixelFormat pf in indexedPixelFormats) { if (pf.Equals(imgPixelFormat)) return true; } return false; }
- Bitmap添加水印提示【无法从带有索引像素格式的图像创建Graphics对象】
- 无法从带有索引像素格式的图像创建 Graphics 对象
- 无法从带有索引像素格式的图像创建 Graphics 对象。
- "无法从带有索引像素格式的图像创建graphics对象"
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象
- 绘图操作时报错“无法从带有索引像素格式的图像创建 Graphics 对象”
- .net下灰度模式图像在创建Graphics时出现:无法从带有索引像素格式的图像创建graphics对象 问题的解决方案。
- Graphics 不能建立有索引像素格式的对象
- C# :实现水印与图片合成,并利用Graphics 压缩图像质量 , (委托实现listBox的动态添加提示)
- 关于无法从带INDEX格式的GIF图片创建Graphics的解决方案
- c#_具有索引像素格式的图像不支持 SetPixel
- System.Drawing.Graphics读取带有索引的图片及思考
- C#从给定的byte数组创建Bitmap对象
- EXCEL打印表格时如何添加带有公司名称的水印
- [体感游戏]关于体感游戏的一些思考(四) --- 克隆战争!
- PHP压缩html网页代码(清除空格,换行符,制表符,注释标记)
- 在Firebug中调试CSS
- 天下3手动更新
- poj1258 最小生成树krus
- Bitmap添加水印提示【无法从带有索引像素格式的图像创建Graphics对象】
- [体感游戏]关于体感游戏的一些思考(五) --- 导航
- linux tar指令
- 【兴趣爱好】之:ACE介绍
- jquery事件处理函数
- [体感游戏]关于体感游戏的一些思考(六)--- 飞行
- 韩顺平网页第二十一讲
- 悬浮窗
- MINA 框架简介