c# 如何将Bitmap转换Image 给我个样例程序
展开全部
不需要啊 直接image=bitmap就可以了啊
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Bitmap b = new Bitmap(“路径”);
Image i = b;
Image i = b;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
生成验证码的示例:
需要添加引用:
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
/// <summary>
/// 产生一个图片验证码
/// </summary>
private void CreateCheckCodeImage()
{
#region 产生一个图片验证码,并且在内存中输出
using (Bitmap image = new Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22))
{
using (Graphics g = Graphics.FromImage(image))
{
//生成随机生成器
Random random = new Random();
//清空图片背景色
g.Clear(Color.White);
//画图片的背景噪音线
for (int i = 0; i < 4; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
}
//图片的字体
Font font = new Font("Arial", 12, (FontStyle.Bold));
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
LinearGradientBrush brush = new LinearGradientBrush(rectangle, Color.Blue, Color.DarkRed, 1.2f, true);
//画图片的字符串(就是验证码字符)
g.DrawString("1223", font, brush, 2, 2);
//画图片的前景噪音点
for (int i = 0; i < 12; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
//画图片的边框线
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
//将图片输出
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
}
}
#endregion
}
需要添加引用:
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
/// <summary>
/// 产生一个图片验证码
/// </summary>
private void CreateCheckCodeImage()
{
#region 产生一个图片验证码,并且在内存中输出
using (Bitmap image = new Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22))
{
using (Graphics g = Graphics.FromImage(image))
{
//生成随机生成器
Random random = new Random();
//清空图片背景色
g.Clear(Color.White);
//画图片的背景噪音线
for (int i = 0; i < 4; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
}
//图片的字体
Font font = new Font("Arial", 12, (FontStyle.Bold));
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
LinearGradientBrush brush = new LinearGradientBrush(rectangle, Color.Blue, Color.DarkRed, 1.2f, true);
//画图片的字符串(就是验证码字符)
g.DrawString("1223", font, brush, 2, 2);
//画图片的前景噪音点
for (int i = 0; i < 12; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
//画图片的边框线
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
//将图片输出
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
}
}
#endregion
}
追问
所答非所问
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询