2013-12-18 58 views
1
Imports System.Drawing.Imaging 
Imports System.Runtime.InteropServices 
Imports System.IO 
Public Class Form1 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    ' Dim OpenFileDialog1 As OpenFileDialog 
    'If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then 
    'PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName) 
    'End If 
Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog 

    ' Set filter options and filter index. 
openFileDialog1.Filter = "BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*" 
openFileDialog1.FilterIndex = 1 

openFileDialog1.Multiselect = True 

    ' Call the ShowDialog method to show the dialogbox. 
Dim UserClickedOK As Boolean = openFileDialog1.ShowDialog 
PictureBox1.Image = Image.FromFile(openFileDialog1.FileName) 
End Sub 
End Class 

使用这段代码,我可以跟踪和打开图像。现在我想访问图像的数据并想要显示。为此,我必须将图像转换为文本文件。这怎么可能?。在C#中有函数Readimage。什么函数将帮助我在VB中读取图像?如何将BMP图像文件转换为VB中的文本文件

+0

您不能将位图转换为文本文件,除非它是ASCII艺术! http://upload.wikimedia.org/wikipedia/commons/a/a3/ASCII_Panzer_unt_Sattelzug.png –

+0

是的,他可以通过将其读入Byte数组,然后创建一个包含该内容的.txt文件。但是文本文件的内容将完全不可读。 – equisde

回答

0

我想你需要使用File.ReadAllBytes打开一个二进制文件,将文件的内容读入一个字节数组,然后关闭文件。

Dim data() as Byte = File.ReadAllBytes(path) 
+0

谢谢你的工作。我可以读取数据。 – user3064718

+0

是否可以使用readline,readtext等其他函数进行读取。 – user3064718

+0

完全没有。这些函数不会接受位图文件。请接受答案,并upvote,如果它帮助你:) – equisde

相关问题