当ImageLocation不起作用时,如何在C#中获取PictureBox的imageURL?
当ImageLocation不起作用时,如何获取windows窗体中图片框的图像URL?
string filepath = picturebox.ImageLocation; // Returns null
How to get the image URL of a picture box in windows form when ImageLocation doesn't work?
string filepath = picturebox.ImageLocation; // Returns null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您使用 picturebox 的 ImageLocation 属性来加载图像,那么您就会得到您想要的。否则,如果您通过 Image 属性加载它,那么您将不会从 ImageLocation 获取,也不会再次从 Image 获取。
If you use the ImageLocation property of picturebox to load the image, then you get what you want. Other wise if you load it via Image property then you wont get from ImageLocation and neither from Image again.
您可以通过
查看 http://msdn 获得该信息.microsoft.com/en-us/library/system.windows.forms.picturebox.imagelocation.aspx
you can get that via
see http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.imagelocation.aspx
图像位置
ImageLocation
也许这篇文章可以帮助您http://blogs.msdn.com/b/marcelolr/archive/2007/06/15/data-binding-a-winforms-picturebox-to-a-file-path-or-url。 aspx
干杯
May be this post can help you http://blogs.msdn.com/b/marcelolr/archive/2007/06/15/data-binding-a-winforms-picturebox-to-a-file-path-or-url.aspx
cheers
听起来你需要:
Sounds like you need:
最后我找到了解决方案。当我们选择图像时,将
Image
的路径存储在图片框的Tag
属性中。并在需要时检索它:
请记住,您必须在清除时将
Tag
属性设置为null
。Finally I found a solution. Store the path of the
Image
in theTag
property of the picture box, when we select the image.And retrive it when you need it:
Remember, you have to set the
Tag
property tonull
on clearance.将图像分配给 PictureBox 需要遵循一定的方法才能正确完成。
我相信阅读此答案后您会理解使用 PictureBox.ImageLocation 背后的原因和逻辑。
当你得到一个 Image.FromFile;您将需要指定一个字符串,其中包含文件:所选图像的目录、文件名和扩展名。
因此,一旦您选择/加载要加载的图像(假设您将使用 OpenFileDialog);您必须首先将文件完整路径设置为 PictureBox.ImageLocation 属性(这样您就可以在需要时检索它);然后(最好)您可以将图像加载到 PictureBox 中。
请参见下面的示例:
如果您需要获取 PictureBox 图像位置:
写下此内容后;您就得到了逻辑,并且最终变得非常简单。
Assigning an Image to PictureBox has a certain methodology to be done correctly.
I'm sure you'll understand the reason and logic behind using the PictureBox.ImageLocation after reading this answer.
When you get an Image.FromFile; you will be required to specify a string, containing the file: Directory, FileName and Extension of the selected Image.
Therefore, once you select/load the Image to be loaded (assuming you'll be using OpenFileDialog); you have to set the file full path to the PictureBox.ImageLocation property in first place (this way you will be able to retrieve it whenever needed); and only then (preferably) you can load the Image to your PictureBox.
See example bellow:
In case you require to get the PictureBox Image Location:
After you write this down;you get the logic and it ends up in being really easy.