如何从文件夹动态读取图像文件 [英] How to readimage files dynamically from a folder

查看:107
本文介绍了如何从文件夹动态读取图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何读取位于D:/Image文件夹中的图像文件

How to read image files located in D:/Image folder

推荐答案

如果您要直接显示图像,则可以轻松指定图像的路径作为C#中图像对象的来源,如

IF you you want to directly show the image you can easily specify the path of the image as source of image object in C# as

Image myImg = Image.FromFile("path here");
Bitmap myBmp = Bitmap.FromFile("path here");



另外,也可以使用以下方式加载位图对象:



Alternatively a Bitmap object can also be loaded with:

Bitmap myBmp = new Bitmap("path here");



或打开图像对话框



Or to open a dialog box for image

Bitmap loadedBitmap = Bitmap.FromFile(openFileDialog1.Filename);



或者,如果您要将图像保存在数据库中或想在内存流中读取图像,请尝试以下

返回基础知识–将文件读入内存流 [



Or if you want to save your image in DB or want to read it in a Memory stream try this

Back to Basics – Reading a File into Memory Stream[^]


只需完成定义的图像即可:
Simply by doing for a defined image:
Image img = new Image();
img.ID = "myImage";
img.ImageUrl = @"D:/Images/Someimage.png":



要选择所有图像,您需要使用DirectoryInfo和FileInfo来获取已定义文件夹中的所有文件.根据扩展名,读取文件. (您需要的图片扩展名.)



To pick all the images, you need to use DirectoryInfo and FileInfo to get all the files in the defined folder. Based on the extension, read the files. (Image extensions in your case.)


这篇关于如何从文件夹动态读取图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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