2013-12-18 61 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

相關問題