如何在VB中将BMP图像文件转换为文本文件

时间:2013-12-18 10:00:04

标签: vb.net image data-conversion

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中读取图像?

1 个答案:

答案 0 :(得分:0)

我认为您需要使用File.ReadAllBytes打开二进制文件,将文件内容读入字节数组,然后关闭文件。

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