vbnet轉(zhuǎn)2進(jìn)制 vb十進(jìn)制轉(zhuǎn)換成二進(jìn)制

vb.net 將文件轉(zhuǎn)化成二進(jìn)制

首先引入System.IO命名空間

創(chuàng)新互聯(lián)公司主營(yíng)梁子湖網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都app軟件開(kāi)發(fā)公司,梁子湖h5微信小程序開(kāi)發(fā)搭建,梁子湖網(wǎng)站營(yíng)銷(xiāo)推廣歡迎梁子湖等地區(qū)企業(yè)咨詢(xún)

Imports System.IO

然后使用文件流來(lái)讀入數(shù)組:

Dim bytes() As Byte

Using fs As New FileStream(文件路徑,FileMode.Open)

ReDim bytes(fs.Length-1)

fs.Read(bytes,0,fs.Length)

fs.Close()

End Using

這樣bytes就是整個(gè)文件的所有字節(jié)了

從字節(jié)生成Image:

Dim img As Image = Image.FromStream(New MemoryStream(bytes))

img就是圖片了

vb.net 圖片轉(zhuǎn)換二進(jìn)制代碼

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim MyStream As New System.IO.MemoryStream

Me.PictureBox1.Image.Save(MyStream, System.Drawing.Imaging.ImageFormat.Jpeg)

Dim MyBytes(MyStream.Length) As Byte

MyStream.Read(MyBytes, 0, MyStream.Length)

MyStream.Close()

Dim strText As String

strText = BitConverter.ToString(MyBytes)

Me.TextBox1.Text = strText

End Sub

vb.net如何將圖片轉(zhuǎn)二進(jìn)制

'容易,用api,查一查SetBitmapBits

'新建工程,增加一個(gè) command button , 一個(gè) picture box , 將圖片加載到 picture box.

'將代碼粘貼到 Form1

Private Type BITMAP

bmType As Long

bmWidth As Long

bmHeight As Long

bmWidthBytes As Long

bmPlanes As Integer

bmBitsPixel As Integer

bmBits As Long

End Type

Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long

Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

Dim PicBits() As Byte, PicInfo As BITMAP, Cnt As Long

Private Sub Command1_Click()

'Get information (such as height and width) about the picturebox

GetObject Picture1.Image, Len(PicInfo), PicInfo

'reallocate storage space

ReDim PicBits(1 To PicInfo.bmWidth * PicInfo.bmHeight * 3) As Byte

'Copy the bitmapbits to the array

GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)

'Invert the bits

For Cnt = 1 To UBound(PicBits)

PicBits(Cnt) = 255 - PicBits(Cnt)

Next Cnt

'Set the bits back to the picture

SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)

'refresh

Picture1.Refresh

End Sub

vb.net 二進(jìn)制讀取文件

VB.NET打開(kāi)二進(jìn)制文件用fileopen完成,打開(kāi)二進(jìn)制文件的形式為:openmode.binary

讀取二進(jìn)制文件用的是fileget方法,寫(xiě)入二進(jìn)制文件用的是fileput方法。

應(yīng)用示例:將一批隨機(jī)數(shù)保存在一個(gè)dat文件中,然后再將其提取到文本框中。

二進(jìn)制文件的讀寫(xiě)一批隨機(jī)數(shù)的存取,程序?yàn)椋?/p>

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim x, i, fn As Integer

Dim s As String = ""

fn = FreeFile()

FileOpen(fn, "d:\data.dat", OpenMode.Binary)

For i = 1 To 8

x = Int(Rnd() * 100)

s = s + Str(x)

FilePut(fn, x)

Next

FileClose(fn)

TextBox1.Text = s

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim x, fn As Integer

Dim s As String = ""

fn = FreeFile()

FileOpen(fn, "d:\data.dat", OpenMode.Binary)

Do While Not EOF(fn)

FileGet(fn, x)

s = s + Str(x) + " "

Loop

FileClose(fn)

TextBox1.Text = s

End Sub

標(biāo)題名稱(chēng):vbnet轉(zhuǎn)2進(jìn)制 vb十進(jìn)制轉(zhuǎn)換成二進(jìn)制
URL網(wǎng)址:http://www.muchs.cn/article40/doocjeo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、網(wǎng)站維護(hù)、建站公司、網(wǎng)站設(shè)計(jì)、商城網(wǎng)站、

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司