如何在c#中获取图片框图像名称 [英] how to get picture box image name in c#

查看:461
本文介绍了如何在c#中获取图片框图像名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在c#.net

解决方案

中获取图片框图片名称如果您的意思是我想在PictureBox中获取图片的文件名,那么你不能,除非你以前保存过它。

图像不会返回它的源文件,因为它不一定来自源文件 - 它可以是相机来源,桌面快照,在新位图上绘制,或从视频文件中获取。



此外,图像没有Name属性,因为它不能直接显示 - 它不是从Control派生的。

它有一个Tag属性,你可以在创建Image时用一个名字设置。


如果您的图像保存在您的计算机中,然后在pictureBox中显示,此代码将有所帮助。



如果您获得了图像的地址pictureBox,你可以使用下面的代码来获取文件名。



string address = @ C:\mydir\myfile.jpg;
string 结果;

result = Path.GetFileName(地址);





如果你没有地址在pictureBox中,你可以使用这个方法获取fileAddress:

 PictureBox.ImageLocation(); 



然后使用Path.GetFileName()方法


I would like to get picture box image name in c#.net

解决方案

If you mean "I want to get the file name for the Image in a PictureBox", then you can't, unless you have previously saved it.
An Image doesn't refer back to it's source file, because it doesn't necessarily come from a source file in the first place - it could be camera sourced, desktop snapshot, drawn on a new bitmap, or taken from a video file.

Additionally, an Image does not have a Name property, because it can't be displayed directly - it is not derived from Control.
It does however have a Tag property, that you could set with a name when you create the Image.


If your image is saved in your computer then shows in pictureBox, this code will be helpful.

If you got the address of image shown in pictureBox, you can use below code to get the file name.

string address = @"C:\mydir\myfile.jpg";
string result;

result = Path.GetFileName(address);



And if you don't have the address of image in pictureBox, you can use this method to get fileAddress:

PictureBox.ImageLocation();


Then use the Path.GetFileName() method.


这篇关于如何在c#中获取图片框图像名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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