返回位图文件的名称c# [英] Return name of Bitmap file c#

查看:92
本文介绍了返回位图文件的名称c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从驱动器上的文件中加载图片。在此之后,我单击一个按钮将此文件添加到列表中并将其显示在列表框中。将文件添加到列表的代码如下所示:

I am loading a picture from a file on my drive. After this, I click a button to add this file to a list and show it in a listbox. The code for adding the file to list looks like:

listbox1.Items.Clear();
mainlibrary.AddPicture((Bitmap)Image.FromFile(picfilename)); //method adds loaded file to list
foreach (Bitmap item in mainlibrary.GetPictureList()) //gets all items in list
{
  listbox1.Items.Add(item.ToString());
}



我遇到的问题是代码将System.Drawing.Bitmap返回到listbox1,但是我想查看名称位图文件,而不是像banana.jpg。我怎么能实现这个或者我做错了什么?



谢谢。


The problem I'm having is that the code returns "System.Drawing.Bitmap" to listbox1, but I want to see the name of the bitmap file instead like "banana.jpg". How can I achieve this or what am I doing wrong?

Thank you.

推荐答案

A Bitmap object没有将它与可能已加载的文件相关联的属性。您可以创建一个继承Bitmap并添加此额外属性的新类。
A Bitmap object has no property that associates it with the file it may have been loaded from. You could create a new class that inherits Bitmap and add this extra property.


位图没有拥有文件名 - 从文件加载它不是创建文件的唯一方法一。实际上,Image.FromFile使用本机Windows调用来加载文件 - 这会创建一个流并从中读取它。



如果你想保留一个文件名在位图数据中,您必须创建自己的类(可能从Image或Bitmap派生),这会添加额外的信息。
A bitmap doesn't "have" a file name - loading it from a file is not the only way to create one. In fact, Image.FromFile uses native windows calls to load the file - which creates a stream and reads it from that.

If you want to keep a file name with the bitmap data, you will have to create your own class (possibly derived from Image or Bitmap) which adds the extra information.


这篇关于返回位图文件的名称c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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