English 中文(简体)
加上从档案到图像阵列的若干jpg
原标题:Add several .jpg s from file to image array

I ll keep this short and simple... I asked this question before, but It wasn t answered. I d like to get several images from a folder, and add them to an array. This is not working, can someone explicitly tell me how to do it? Thanks!

表格装载:

Private Sub Button1_Add(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim PictureArray As New List(Of Image)
    For Each item As String In Directory.GetFiles("C:Users	urcotdDesktopITLPers", "*.jpg", IO.SearchOption.AllDirectories)
        Dim _Image As Image = Image.FromFile(item)
        PictureArray.Add(_Image)
    Next

    If (i < 6) Then
        Dim pb As New PictureBox
        Me.FlowLayoutPanel1.Controls.Add(pb)
        pb.Image = PictureArray(i)
        i = i + 1

enter image description here Thanks!!!

最佳回答

首先,i ve向您展示了如何获取DirectoryInfo 。 不要从上述档案信息中找到!

I ve在 回答您先前的问题,而不是“Array” ,因为这是一个好兆头, rel=“nofollow noretinger” ,甚至比“ArrayList。 您可以查阅清单中的物品,也可查阅阿雷拉(通过索引或“前列”)中的物品。

If you anyway insist on using an Array, you simply need to use the ToArray-Extension instead of ToList. For example:

Dim imageArray = dir.GetFiles("*.jpg", IO.SearchOption.AllDirectories).ToArray

Look at the FileInfo-Class for further informations. For example you need to call FileInfo.Name to get the image-name(filename without path) or FileInfo.FullName to get the Full-Path.

因此,这项工作应当:

Dim dir = New IO.DirectoryInfo("C:Users	urcotdDesktopITLPers")
Dim images = dir.GetFiles("*.jpg", IO.SearchOption.AllDirectories).ToList
Dim pictures As New List(Of PictureBox)
For Each img In images
    Dim picture As New PictureBox
    picture.Image = Image.FromFile(img.FullName)
    pictures.Add(picture)
Next
问题回答

An image is not a datatype you can use fileinfo to read the images into an byte array.

Tim s answer here at your previous question does that very well it just puts it into a list. You can then call thelist.toarray and now your list is an array.

EDIT: i found this link for you it will help.

http://www.codeproject.com/KB/vb/ImageProccessing.aspx

这是一个很简单的过程。

问题在于你把形象视为一种扼杀或煽动,而不是一种。 它是一批 by。 这种希望有助于。

btn26 code is what i am referring Dear friend Growler, I have enclosed a button_Click code which perfectly picks the right image from the right path and loads to pdf.I also have some text transfered from multiline textbox to a richtextbox which goes 1st to pdf followed by images. Your code and the and the corrections given are not working.I am using VS 2017 community as backup and use VB.Net 14 (windows 10 goes without saying).I have given 2 screenshots also. btn26 is the button.I have enlrged the code portion so that i need not write it again. Regards kvinvisibleguy

“Image

This is the pdf image.I have just shown you one image with some text 
at the end of my xaml file.The 2nd image is just below the image shown.
Regards




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签