如何在数组中排列字节信息。 [英] How to arrange byte information in an array.
本文介绍了如何在数组中排列字节信息。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
截至目前,我一直在尝试将我的图片作为数组排列在字节中。我希望以水平方式将所选图片添加到同一行。问题是当我将其设置为数组时,图像垂直添加,每行1个。我需要将我选择的所有图像添加到同一行。该列本身不需要名称。
As of right now I have been trying to arrange my pictures that are in byte for as an array. I want the selected pictures to be added to the same row in a horizontal fashion. Problem is when I set this up as an array the images are added vertically, 1 per row. I need to have all images I select to be added to the same row. The column itself does not need a name.
Imports System.IO
Public Class Form1
Dim ofd As New OpenFileDialog With {.Filter = "Images|*.jpg;*.bmp;*.png;*.gif;*.wmf"}
Dim pic As PictureBox
Dim wid As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'this portion of code allows users to browse for images and add them into the group box.
ofd.Multiselect = True
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
For Each t In ofd.FileNames
pic = New PictureBox
pic.Image = Image.FromFile(t)
pic.SizeMode = PictureBoxSizeMode.StretchImage
pic.SetBounds(wid, 20, 200, 100)
wid += 205
AddHandler pic.Click, AddressOf convertPic
Me.Panel1.Controls.Add(pic)
' if you want to add the images straight to the form use: Me.Controls.Add(pic)
' this portion of code attaches the image to the picturebox
PictureBox1.Image = pic.Image
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
' This portion of code allows you to add pictures to the datagrid. you can use the same code to add into an sql statement.
Using ms As MemoryStream = New MemoryStream()
Dim bm As Bitmap = New Bitmap(PictureBox1.Image)
bm.Save(ms, PictureBox1.Image.RawFormat)
Dim arrPic() As Byte = ms.GetBuffer()
DataGridView1.Columns.Add("", "")
DataGridView1.Rows.Add(arrPic.ToArray)
End Using
Next
End If
End Sub
我的尝试:
我试过制作数组列表:
What I have tried:
I have tried to make an array list:
Dim row As New ArrayList
row.Add(arrPic.ToArray)
DataGridView1.Rows.Add(row)
但是当我这样尝试时,字节转换为s系统字符串,无法打开。
but when I try it this way the byte is converted to s systems string and cannot be opened up.
推荐答案
如果您致电Rows.Add
对于每张图片,当您的代码为每张图片添加新行时,不应该感到惊讶。 :)
如果你想将所有图片作为列添加到一行,那么你需要添加一行,并将图像添加到那一行。
If you callRows.Add
for each picture, it shouldn't come as a surprise when your code adds a new row for each picture. :)
If you want to add all of the pictures as columns to a single row, then you'll need to add a single row, and add the images to that row.
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim fileCount = ofd.FileNames.Length
Dim images(fileCount - 1) As Image
For i As Integer = 0 To fileCount - 1
If i >= DataGridView1.Columns.Count Then
Dim col As New DataGridViewImageColumn()
col.Width = 200
DataGridView1.Columns.Add(col)
End If
images(i) = Image.FromFile(ofd.FileNames(i))
Dim pic As New PictureBox()
pic.Image = images(i)
pic.SizeMode = PictureBoxSizeMode.StretchImage
pic.SetBounds(wid, 20, 200, 100)
AddHandler pic.Click, AddressOf convertPic
Me.Panel1.Controls.Add(pic)
wid += 205
Next
' NB: No point doing this in the loop, as only the last one will apply:
PictureBox1.Image = images(fileCount - 1)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
DataGridView1.Rows.Add(images)
End If
这篇关于如何在数组中排列字节信息。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文