删除图片

yanbinquan 2010-05-05 05:01:04
用Graphics.FromImage加载了图片后.
想把加载的图片删除或者隐藏,该怎么做呢?

Image temp = Image.FromFile(@"image\11.jpg");
Graphics g = Graphics.FromImage(temp);
g.DrawImage(temp, 0, 0, temp.Width, temp.Height);

...全文
228 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzx509 2010-05-06
  • 打赏
  • 举报
回复
楼主可以在类中定义一个bool变量表示是否打印状态。如bool isPrinting;
在按下打印按钮后,isPrinting=true;其它状态时设置回false;

temp = Image.FromFile(@"image\农村信用合作社支票.jpg");
Graphics g = Graphics.FromImage(temp);
if(!isPrinting)
{
g.DrawImage(temp, 0, 0, temp.Width, temp.Height);
}
g.DrawString(DateTime.Now.Year.ToString(), f1, b, 78, 168);
....................
int x = e.MarginBounds.X;

mngzilin 2010-05-06
  • 打赏
  • 举报
回复
Image bmp= Image.FromFile(@"image\农村信用合作社支票.jpg");
Bitmap temp=new Bitmap(bmp);
bmp.Dispose();
卧_槽 2010-05-06
  • 打赏
  • 举报
回复
你要先创建一个空白的bitmap,作为最终输出。
temp作为一个图层,通过空白bitmap的graphics绘制上去,需要的时候就画,即调用drawimage
不需要的时候,就不画,就好了。
Image temp = Image.FromFile(@"image\农村信用合作社支票.jpg");

Bitmap Outbit=new Bitmap(temp.width,temp.height);
Graphics OutG=Graphics.FromImage(Outbit);
if(调整打印位置)
OutG.DrawImage(temp, 0, 0, temp.Width, temp.Height);//如果要调整打印位置执行,否则不执行
.
.
.

手写的代码不知道写错没,大概就这样。
不跟7楼的垃圾计较。
yanbinquan 2010-05-06
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 mngzilin 的回复:]

Bitmap bmp=new bitmap(temp);
temp.dispose();
用bmp进行操作
[/Quote]

不是很懂,能写多点代码吗??
我新手!!
mngzilin 2010-05-06
  • 打赏
  • 举报
回复
Bitmap bmp=new bitmap(temp);
temp.dispose();
用bmp进行操作
yanbinquan 2010-05-06
  • 打赏
  • 举报
回复
谢谢楼上各位.
我想做的是支票打印.
我加载图片是为了方便调整打印位置.
最后打印的时候不需要那图片,要把它隐藏或者删除.

temp = Image.FromFile(@"image\农村信用合作社支票.jpg");
Graphics g = Graphics.FromImage(temp);
g.DrawImage(temp, 0, 0, temp.Width, temp.Height);
g.DrawString(DateTime.Now.Year.ToString(), f1, b, 78, 168);
....................
int x = e.MarginBounds.X;
int y = e.MarginBounds.Y;
int width = temp.Width;
int height = temp.Height;
Rectangle destRect = new Rectangle(x, y, width, height);
e.Graphics.DrawImage(temp, destRect, 0, 0, temp.Width, temp.Height, System.Drawing.GraphicsUnit.Pixel);

aonate11o 2010-05-06
  • 打赏
  • 举报
回复
对象.Dispose();处理掉它
mngzilin 2010-05-05
  • 打赏
  • 举报
回复
如梦的答案正确,我的答案也是啊,哈哈!~~~
mngzilin 2010-05-05
  • 打赏
  • 举报
回复
Image temp = Image.FromFile(@"image\11.jpg");
Graphics g = Graphics.FromImage(new Bitmap(temp));
g.DrawImage(temp, 0, 0, temp.Width, temp.Height);
wuyq11 2010-05-05
  • 打赏
  • 举报
回复
temp.Dispose()
蔡袅 2010-05-05
  • 打赏
  • 举报
回复
你可以再隐藏或者删除图片的事件触发时,把欲填充图片到某个对象的填充源给去掉就可以了~
yongchaochu 2010-05-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ciwei6744 的回复:]
引用 3 楼 yuwenge 的回复:

问问题的傻,答题的更是。。。

装什么装,又能耐你把问题解决了,垃圾一个
[/Quote]
话说 这位真没素质
ciwei6744 2010-05-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yuwenge 的回复:]

问问题的傻,答题的更是。。。
[/Quote]
装什么装,又能耐你把问题解决了,垃圾一个
qldsrx 2010-05-05
  • 打赏
  • 举报
回复
你把temp变量dispose一下,就可以删除调用的那个文件了,只不过释放了资源,temp对应的图片对象也不见了,所以你除非先复制到内存中,或者确定肯定不需要使用了,才能这么做。
June1991 2010-05-05
  • 打赏
  • 举报
回复
LZ想要实现个什么功能呢?
卧_槽 2010-05-05
  • 打赏
  • 举报
回复
问问题的傻,答题的更是。。。
yanbinquan 2010-05-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 juedaihuaihuai 的回复:]

Graphics.FromImage(null)
[/Quote]
提示错误:值不能为空。

编译不成功哦!!
绝代坏坏 2010-05-05
  • 打赏
  • 举报
回复
Graphics.FromImage(null)

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧