473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to read bmp image data in VB.Net

I'm working on image recognition which needs to be fast. From what I know the speed of using a memory stream is much faster than using .GetPixel for bitmaps

But when I use the memory stream I'm getting different results. I'm sure it's to do with how I'm creating and reading the stream. Can anyone assist with the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ScanImageShape(ByRef bMap As Bitmap)
  2.         Dim lOffset As Long     'The length of the bmp header
  3.         Dim lPos As Long
  4.         Dim x As Integer
  5.         Dim y As Integer
  6.  
  7.         'Get a memory stream into a byte array.
  8.         Dim imgByteArray() As Byte
  9.         Dim msBitmap As New IO.MemoryStream
  10.  
  11.         Dim bRed As Byte
  12.         Dim bGreen As Byte
  13.         Dim bBlue As Byte
  14.         Dim cPixel As Color
  15.  
  16.         'Put the bitmap into the memory stream
  17.         bmap.Save(msBitmap, ImageFormat.Bmp)
  18.  
  19.         'Load memory stream into byte array
  20.         imgByteArray = msBitmap.GetBuffer
  21.  
  22.         'This is the starting byte position of the bitmap data, after the header (???)
  23.         lOffset = 54
  24.         For y = 0 To bmap.Height - 1  '240
  25.             For x = 0 To bmap.Width - 1  ' 320
  26.                 'Assume that there are 4 bytes per pixel
  27.                 lPos = (y * 96) + (x * 4) + lOffset
  28.                 cPixel = bmap.GetPixel(x, y)
  29.  
  30.                 bBlue = imgByteArray(lPos).ToString
  31.                 bGreen = imgByteArray(lPos + 1).ToString
  32.                 bRed = imgByteArray(lPos + 2).ToString
  33.  
  34.                 'Insert BYTE values into a multiline text box
  35.                 txtDebugCoords.AppendText(lPos.ToString + ", " + _
  36.                                           x.ToString + ", " + _
  37.                                           y.ToString + ", " + _
  38.                                           bBlue.ToString + ", " + _
  39.                                           bGreen.ToString + ", " + _
  40.                                           bRed.ToString + Environment.NewLine)
  41.  
  42.  
  43.                 'In another multiline text box compare the "getpixel" values. Should be the same.
  44.                 txtDebugBMP.AppendText(bmap.GetPixel(x, y).B.ToString + ", " + _
  45.                                        bmap.GetPixel(x, y).G.ToString + ", " + _
  46.                                        bmap.GetPixel(x, y).R.ToString + Environment.NewLine)
  47.  
  48.             Next
  49.         Next
  50.  
  51.         msBitmap = Nothing
  52.  
  53.     End Sub
Aug 4 '10 #1
0 1608

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
3
by: Defcon31 | last post by:
hello i receive from a dll a pointer to raw image data (307200bytes grayscale values). can someone explain how i can put this image data in a picturebox in VB? or can someone post code to do it...
0
by: Thomas | last post by:
Hi all, I'm in search of a fast solution to reading image dimensions. I know you can get the image dimensions by loading a file into an image object, and then reading the height/width...
3
by: Steve Tooke | last post by:
I'm trying to find a way to quickly read image headers (specifically jpgs at the moment) with out loading the whole image as an System.Imaging.Image. Anybody point me in the right direction or am I...
4
by: Andy | last post by:
Hello All: I have a field in the database that is an Image. I have no idea how the data is stored in here (Image, compressed, encrypted, plain text, etc). I am trying to write the contents to...
10
by: mattmerc | last post by:
Hi all, I posted this about a week back with no response so I want to try again. I have a weird questions in regards to working with sql image data types. I know how to take the image type and...
2
by: Chucker | last post by:
Hi Community, I think I can store Binary Data in SQL Server but when I try to retrieve it, I always only get one byte. I think I stored my Binary Data in SQL Server in a Colum of Type Image....
2
by: Ed | last post by:
Hope someone can help me out... I have been tasked to read some image data from an sql database and save the files to flat files. OK, sounds easy as I'v used BLOBs before. But this is an old...
1
by: doubts | last post by:
Hi, I have a query regarding reading Image Property for button from a XML file . I read XML files to Generate Screens using System.Windows.Forms.Controls .The XML file is read and properties...
11
by: eddiefisher41 | last post by:
Hey Guys. I'm looking for some info on how to read binary image data. Basicly RAW image files are strings of bits with say 2 bytes per pixel. What i need to do is read the value of each pixel in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.