PictureBox和ThumbNail代码导致应用程序不关闭。 [英] PictureBox and ThumbNail code causing Application to NOT close.

查看:42
本文介绍了PictureBox和ThumbNail代码导致应用程序不关闭。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码将来自ImageList的缩略图附加到PictureBox。但是,一旦代码块被执行,它就会导致我的应用程序无法关闭。我怀疑这与资源(照片文件)没有正确发布有关,但我可能错了。任何专家建议将不胜感激。一切顺利!

< br /> Image.GetThumbnailImageAbort myCallback =< br /> new Image.GetThumbnailImageAbort(ThumbnailCallback);< br /> Image myThumbnail = this.imageList1.Images [0] .GetThumbnailImage(this.pictureBox1.Size.Width-5,this.pictureBox1.Size.Height-5,myCallback,IntPtr.Zero);< br /> // e .Graphics.DrawImage(myThumbnail,150,75);< br /> < br /> this.pictureBox1.Image = myThumbnail;< br /> this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;

解决方案

该代码适用于我。

 public partial class Form1:Form< br /> {< br /> public Form1()< br /> {< br /> InitializeComponent();< br />< br /> Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);< br /> Image myThumbnail = this.imageList1.Images [0] .GetThumbnailImage(this.pictureBox1.Size.Width  -  5,this.pictureBox1.Size.Height  -  5,myCallback,IntPtr.Zero);< br /> this.pictureBox1.Image = myThumbnail;< br /> this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;< br /> }< br />< br /> private bool ThumbnailCallback()< br /> {< br />返回true;< br /> }< br /> } 


并且应用程序退出正常。

退出失败通常是由于线程无法正常终止。您的中止回调是否被触发?它是否正确返回?

您无需释放图像。这是由Imagelist为您处理的,前提是您已经通过设计器添加了图像列表或者手动正确处理它,无论哪种方式,这都不会阻止您的应用关闭。

关闭后你的应用程序,它被卡住而没有终止,尝试按下暂停按钮并查看调用堆栈以查看它被卡住的位置。搜索结果


<小> <大> <大> <>

I've got the following code that attaches a thumbnail image coming from an ImageList to a PictureBox. However, it is causing my application to not close once the code block gets executed. I suspect this has got to do with the resource(the photo file) not being released properly, I may be wrong though. Any experts advice would be greatly appreciated. All the best!

<br /> Image.GetThumbnailImageAbort myCallback =<br /> new Image.GetThumbnailImageAbort(ThumbnailCallback);<br /> Image myThumbnail = this.imageList1.Images[0].GetThumbnailImage(this.pictureBox1.Size.Width-5, this.pictureBox1.Size.Height-5, myCallback, IntPtr.Zero);<br />// e.Graphics.DrawImage(myThumbnail, 150, 75);<br /> <br /> this.pictureBox1.Image = myThumbnail;<br /> this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;

解决方案

The code works fine for me.

public partial class Form1 : Form<br />    {<br />        public Form1()<br />        {<br />            InitializeComponent();<br /><br />            Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);<br />            Image myThumbnail = this.imageList1.Images[0].GetThumbnailImage(this.pictureBox1.Size.Width - 5, this.pictureBox1.Size.Height - 5, myCallback, IntPtr.Zero);<br />            this.pictureBox1.Image = myThumbnail;<br />            this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;<br />        }<br /><br />        private bool ThumbnailCallback()<br />        {<br />            return true;<br />        }<br />    }


And the app exits fine.

Failure to exit is usually caused by a thread not terminating correctly. Does your abort callback get triggered? Does it correctly return?

You don't need to release the Image. This is handled by the Imagelist for you provided that you have added your image list via the designer or correctly disposed of it manually, either way though, this wouldn't prevent your app from closing.

After you have closed your app, and it's stuck without terminating, try hitting the pause button and looking at the call stack to see where it is stuck.


<>


这篇关于PictureBox和ThumbNail代码导致应用程序不关闭。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆