這兩天在弄 uEye CCD 終於成功了,但也告訴我必須要放棄

由於用的CCD是黑白的CCD,如果是彩色那還沒問題,但問題是黑白
在VB.net中提供的Bitmap的格式並沒有8 Byte的灰階 只有 8byte 指標的256色
由記體體中取出的資料是沒問題的
由uEye提供的Function取得指標

dim lpt as lptPtn
iss_GetImageMem(1, lpt) <----取得指標
再用
bmp2 = New Bitmap(640, 480, 640, Imaging.PixelFormat.Format8bppIndexed, lpt)
將記憶體的資料存到 bitmap

由於沒有8 bytes 的灰階 存的圖顏色會有問題
又不能直接修改 pixel 的顏色
必須先轉換到 24RGB

Dim bmp4 = New Bitmap(640, 480, Drawing.Imaging.PixelFormat.Format24bppRgb)
g1 = Graphics.FromImage(bmp4)
g1.PageUnit = GraphicsUnit.Pixel
g1.DrawImageUnscaled(bmp2, 0, 0)

再轉換為灰階

bmp1= GetGrayBitmap(bmp4)

Private Function GetGrayBitmap(ByVal bmp As Bitmap)
For Me.i = 0 To bmp.Width - 1
For Me.j = 0 To bmp.Height - 1
co = bmp.GetPixel(i, j)
gray = (co.R * 0.3 + co.G * 0.59 + co.B * 0.11)
bmp.SetPixel(i, j, Color.FromArgb(gray, gray, gray))
Next
Next
Return bmp
End Function

要的目的已經做到了,Londing非常重 系統會鈍鈍的,這還是縮小畫格
用原來的1280*1024,系統還會當 目前放棄動態量測的功能.........................



ps 一開始是用
Dim bytes As Integer = 640 * 480
Private Shared test(640 * 480) As Byte

Dim lpt As IntPtr
Dim rect As New Rectangle(0, 0, 640, 480)


Dim bmpData As System.Drawing.Imaging.BitmapData = bmp2.LockBits(rect, _Drawing.Imaging.ImageLockMode.ReadWrite, bmp2.PixelFormat)
iss_GetImageMem(1, lpt)
ptr = bmpData.Scan0
System.Runtime.InteropServices.Marshal.Copy(lpt, test, 0, bytes)
System.Runtime.InteropServices.Marshal.Copy(test, 0, ptr, bytes)
bmp2.UnlockBits(bmpData)
用兩次指標 由記憶體中先讀到陣列 test 再存到 bitmap 速度比較慢
文章標籤
全站熱搜
創作者介紹
創作者 Rh 的頭像
Rh

程式狂想曲

Rh 發表在 痞客邦 留言(1) 人氣(1,111)