生成水印图片是出现这个问题!(无法从带有索引像素格式的图像创建 Graphics 对象。)
2008-10-14 17:58
477 查看
主要原因就是上传的图片原类型是GIF型就不行,所以要先转位图,将原图像画到位图上,再保存位图
/// <summary>
/// 给图片加水印
/// </summary>
/// <param name="strPath">原始文件</param>
/// <param name="strPathSyp">水印文件</param>
/// <param name="strPathSypf">加水印后的结果文件</param>
public static void AddWaterPic(string strPath, string strPathSyp, string strPathSypf)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(strPath);
Bitmap bm = new Bitmap(image);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile(strPathSyp);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bm);
//如果要使水印居中显示,只要更改bm.Width - copyImage.Width, bm.Height - copyImage.Height,这两个值
//就可以了,在实际项目中,我用的是Convert.ToInt32(image.Width * 0.3), Convert.ToInt32(image.Height * 0.3)
g.DrawImage(copyImage, new System.Drawing.Rectangle(bm.Width - copyImage.Width, bm.Height - copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, System.Drawing.GraphicsUnit.Pixel);
g.Dispose();
copyImage.Dispose();
bm.Save(strPathSypf);
bm.Dispose();
}
/// <summary>
/// 给图片加水印
/// </summary>
/// <param name="strPath">原始文件</param>
/// <param name="strPathSyp">水印文件</param>
/// <param name="strPathSypf">加水印后的结果文件</param>
public static void AddWaterPic(string strPath, string strPathSyp, string strPathSypf)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(strPath);
Bitmap bm = new Bitmap(image);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile(strPathSyp);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bm);
//如果要使水印居中显示,只要更改bm.Width - copyImage.Width, bm.Height - copyImage.Height,这两个值
//就可以了,在实际项目中,我用的是Convert.ToInt32(image.Width * 0.3), Convert.ToInt32(image.Height * 0.3)
g.DrawImage(copyImage, new System.Drawing.Rectangle(bm.Width - copyImage.Width, bm.Height - copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, System.Drawing.GraphicsUnit.Pixel);
g.Dispose();
copyImage.Dispose();
bm.Save(strPathSypf);
bm.Dispose();
}
相关文章推荐
- 给图片添加水印,解决GIF添加水印的问题(无法从带有索引像素格式的图像创建 Graphics 对象)
- .net下灰度模式图像在创建Graphics时出现:无法从带有索引像素格式的图像创建graphics对象 问题的解决方案。
- .net下灰度模式图像在创建Graphics时出现:无法从带有索引像素格式的图像创建graphics对象 问题的解决方案。
- .net下灰度模式图像在创建Graphics时出现:无法从带有索引像素格式的图像创建graphics对象 问题的解决方案。
- Bitmap添加水印提示【无法从带有索引像素格式的图像创建Graphics对象】
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象|A Graphics object cannot be created from an image that has an indexed pixel format
- (转载)无法从带有索引像素格式的图像创建graphics对象|A Graphics object cannot be created from an image that has an indexed pixel format
- 绘图操作时报错“无法从带有索引像素格式的图像创建 Graphics 对象”
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象(转)
- 无法从带有索引像素格式的图像创建 Graphics 对象。
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象
- "无法从带有索引像素格式的图像创建graphics对象" 解决
- 无法从带有索引像素格式的图像创建graphics对象
- "无法从带有索引像素格式的图像创建graphics对象"
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象