close

當bitmap Lockbit 時 有三種屬性可以選擇

ImageLockMode.ReadWrite                可讀可寫
ImageLockMode.ReadOnly                 只可讀
ImageLockMode.WriteOnly                 只可寫
ps 第四種 UserInputBuffer 看不太懂........  )



在效能上  使用沒有感覺,只有使用的模式的差別

Lock bit後需要可以用  Marshal.Copy 倒出  陣列
倒出陣列後要計算每個pixel 的值   需要知道一開始的  PixelFormat


PixelFormat.Format24bppRgb       24/8 = 3 bytes
PixelFormat.Format16bppRgb       24/8 = 2 bytes
PixelFormat.Format8bppIndexed  8/8   = 1 bytes

如果一張 100*100 的 24bit 的圖
在一開始宣告陣列的長度  

Dim bits = 100*100 * 8  (共80000個)

Dim tempbitmap As Imaging.BitmapData = bmSnap.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
System.Runtime.InteropServices.Marshal.Copy(tempbitmap.scan0, rgbValue, 0, bits)
bmSnap.UnlockBits(tempbitmap)



BitmapData 物件有幾個參數很好用

tempbitmap.Scan0        <---取得圖片記憶體指標(記憶體的第一個位置)
tempbitmap.Width        <---取得圖片的寬度
tempbitmap.Height       <---取得圖片的高度
tempbitmap.Stride        <---取得單Row 的寬度


.Stride  並不一定 =  width * bytes
(ps bytes = 圖片的 bit / 8 )


由於圖片記憶體每行儲存必須為 4的倍數

以25*25 24bit 為例

圖片單行    為 25*3 = 75 但不能被 4 整除   所以必須存 76  
所以此圖片的           .Stride = 76
但此圖片的     width*bytes = 75


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Rh 的頭像
    Rh

    程式狂想曲

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