vb.net 中,怎样获取内存中图片流的内存首地址及大小?

良朋 2013-12-03 04:52:21
vb.net 中,怎样获取内存中图片流的内存首地址及大小?
Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(File.ReadAllBytes(mFileName))

我把一个图片文件以流的形式读入到内存中,怎样获取它的内存首地址及大小?
...全文
1083 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
良朋 2013-12-09
  • 打赏
  • 举报
回复
这个可以,其实我是想把我用线扫相机扫到的buffer传递给visionPro的cogImage, 唉,一直找不到有关代码。

Private Sub LockUnlockBitsExample(ByVal e As PaintEventArgs)


        Dim bmp As New Bitmap("c:\fakePhoto.jpg")

        ' Lock the bitmap's bits.  
        Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height)
        Dim bmpData As System.Drawing.Imaging.BitmapData = bmp.LockBits(rect, Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat)

        ' Get the address of the first line.
        Dim ptr As IntPtr = bmpData.Scan0

        ' Declare an array to hold the bytes of the bitmap.
        ' This code is specific to a bitmap with 24 bits per pixels.
        Dim bytes As Integer = bmpData.Stride * bmp.Height
        Dim rgbValues(bytes - 1) As Byte

        ' Copy the RGB values into the array.
        System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes)

        ' Set every third value to 255. A 24bpp image will look red.
        For counter As Integer = 2 To rgbValues.Length - 1 Step 3
            rgbValues(counter) = 255
        Next

        ' Copy the RGB values back to the bitmap
        System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes)

        ' Unlock the bits.
        bmp.UnlockBits(bmpData)

        ' Draw the modified image.
        e.Graphics.DrawImage(bmp, 0, 150)

    End Sub


    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        LockUnlockBitsExample(e)
    End Sub
wxyong2sy 2013-12-04
  • 打赏
  • 举报
回复
fs = New FileStream(mFileName, FileMode.Open, IO.FileAccess.Read) Dim file(fs.Length-1) As Byte fs.Read(file, 0, fs.Length) fs.Close() 这是我读任意文件为二进制流的代码,对图片也一样。
红衣老大 2013-12-03
  • 打赏
  • 举报
回复
为啥要获取这个? 要做操图片 没有也能做 另外 vb确实不擅长操作内存 如果一定的要作业的api了

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧