close

在 VB.Net 下 可以利用指標加陣列 取出 圖檔裡的資料

運用:要二值化圖檔

step1 Lockbit 圖檔
step2 取得指標   temp.scan0  
step3 copy
step4 解除lockbit

首先  
imports system.Drawing
imports system.Drawing.imaging



Dim bmtemp as bitmap = image.Fromfile("C:\.........")

Dim bits as integer = bmtemp.weight*bm.Height *3       <---取得圖檔元素     目前定此圖檔是 24bits 的圖
Dim rgbValue(bits -1 ) as byte                                         <---等會要儲存的空間

Dim rect as Rectangle = new Rectangle(0,0,bmtemp.weight,bmtemp.Height)

Dim temp as BitmapData = bmtemp.Lockbit(rect,image,ReadOnly,bmtem.pixelFormat)   <---Lockbit

System.Runtime.InteropServices.Marshal.Copy(temp.scan0,rgbvalue,0,bits)        <--取得指標後   由第1個 到 bits 個  copy到  rgbValue()

bmtemp.unlockBits(temp)


如此  就可以把 圖檔裡 的每個pixel copy 進陣列      速度會比 getpixel 速度快很多










arrow
arrow
    全站熱搜

    Rh 發表在 痞客邦 留言(0) 人氣()