求教 关于GDI+图像方面的问题
思路:类似我们经常在Photoshop里把不同图像分辨率的图片放在同一张图片上。比如:在第一张图片里,分辨率设置成300像素/英寸,在上面 每个5个像素 画出 5黑5白的 竖线,竖线宽度是5个像素。
在第二张图片里,也同样画这样的竖线,不过分辨率设置成400像素/英寸。
在第三张图片里,分辨率设置成600。
。。。。。依次类推。
然后 把这些图片放置在一张图片里,依次顺序往下叠加。
我自己写了个测试代码,可是测试代码总是报错。
这段代码总是在 img2.Save(@"d:\ttttt.bmp", ImageFormat.Bmp); 发生错误。
错误显示如下:
未处理 ExternalException
GDI+ 中发生一般性错误。
也许是我的程序写的不对,也不知道错在哪里,恳请大家帮忙解决。
测试代码如下:
--------------------编程问答-------------------- 专家给力帮忙呀! --------------------编程问答-------------------- 大家帮帮忙啦 --------------------编程问答-------------------- 直接使用内存,干嘛老存取啊,是不是图像仍然被占用啊 --------------------编程问答--------------------
private void button6_Click(object sender, EventArgs e)
{
if (File.Exists(@"d:\ttttt.bmp"))
File.Delete(@"d:\ttttt.bmp");
Bitmap img = new Bitmap(3600, 4800, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(img);
g.Clear(Color.White);
img.Save(@"d:\ttttt.bmp", ImageFormat.Bmp);
g.Dispose();
img.Dispose();
int barHeigh = 30;
Pen pen = new Pen(Color.Black);
pen.Width = 5.0F;
int heigh = 5;
for (float line = 30.0F; line <= 35.0F; line += 0.1F)
{
Bitmap img1 = new Bitmap(@"d:\ttttt.bmp");
Bitmap img2 = new Bitmap(img1);
img2.SetResolution(line * 10, line * 10);
Graphics g1 = Graphics.FromImage(img2);
g1.SetClip(new Rectangle(5, heigh, 600, heigh + barHeigh) );
for (int width = 5; width <= 605; width += 10)
{
g1.DrawLine(pen, new Point(width, heigh), new Point(width, heigh + barHeigh));
}
heigh = heigh + barHeigh + 10;
img2.Save(@"d:\ttttt.bmp", ImageFormat.Bmp);
g1.Dispose();
img2.Dispose();
img1.Dispose();
}
}
使用过直接用内存的情况,并不能改变分辨率的,画出的线都是一抹一样的,不达标 --------------------编程问答-------------------- GDI是针对屏幕设置的,默认的是72dpi吧,你可以把不同Dpi的转换下
比如在400dpi下画5像素宽的直线,如果效果要和屏幕的一样就因该是 400/72 * 5像素宽
补充:.NET技术 , C#