vb.Net streaming bitmaps

Streaming large bitmaps from disk

Page 1 of 1

3 Replies - 2873 Views - Last Post: 22 May 2009 - 11:24 AM Rate Topic: -----

#1 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 13
  • View blog
  • Posts: 602
  • Joined: 18-January 06

vb.Net streaming bitmaps

Post icon  Posted 22 May 2009 - 10:34 AM

Ok, so I am working on a program that alters very large images. The images are usually in .tif or .bmp format. I load up the old image, copy a section of it into a new image, then save the new image. So far everything works

my problem is that the images that i have to alter are 900mb+. Using the simple Bitmap class is not working because the images are quite apparently too large to fit into memory that way. (throwing an OutOfMemory exception)

I want to step over the part of loading the image, and turn it into streaming the pixels from the image straight from the disk. I kind of have an idea of how to get the stream open and start reading, but I have no idea what to do with the 32bit integers that are being returned.

Anyone have any ideas or tutorials on how to stream pixel data from an image??

thnx

Dim oldImage As Bitmap

		Try
			oldImage = New Bitmap(file)
		Catch ex As Exception
			MsgBox("Image is too large! " + ex.Message.ToString(), MsgBoxStyle.Critical)
			Return
		End Try

		Dim newImage As Bitmap = New Bitmap(100, 100)

			' 2:06 to run currently
			' Copy all the appropriate pixels from the old image into the new scene
			While x < 100And y < 100

				newImage.SetPixel(x, y, oldImage.GetPixel(x + offsetX, y + offsetY))
				
				If x = 99 Then
					x = 0
					y += 1
				Else
					x += 1
				End If
			End While


Is This A Good Question/Topic? 0
  • +

Replies To: vb.Net streaming bitmaps

#2 bigtonyk  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 61
  • Joined: 17-May 09

Re: vb.Net streaming bitmaps

Posted 22 May 2009 - 10:46 AM

View Postthe_hangman, on 22 May, 2009 - 09:34 AM, said:

Ok, so I am working on a program that alters very large images. The images are usually in .tif or .bmp format. I load up the old image, copy a section of it into a new image, then save the new image. So far everything works

my problem is that the images that i have to alter are 900mb+. Using the simple Bitmap class is not working because the images are quite apparently too large to fit into memory that way. (throwing an OutOfMemory exception)

I want to step over the part of loading the image, and turn it into streaming the pixels from the image straight from the disk. I kind of have an idea of how to get the stream open and start reading, but I have no idea what to do with the 32bit integers that are being returned.

Anyone have any ideas or tutorials on how to stream pixel data from an image??

thnx

Dim oldImage As Bitmap

		Try
			oldImage = New Bitmap(file)
		Catch ex As Exception
			MsgBox("Image is too large! " + ex.Message.ToString(), MsgBoxStyle.Critical)
			Return
		End Try

		Dim newImage As Bitmap = New Bitmap(100, 100)

			' 2:06 to run currently
			' Copy all the appropriate pixels from the old image into the new scene
			While x < 100And y < 100

				newImage.SetPixel(x, y, oldImage.GetPixel(x + offsetX, y + offsetY))
				
				If x = 99 Then
					x = 0
					y += 1
				Else
					x += 1
				End If
			End While



Streaming the data in is very straightforward, but what the data means is going to depend on the file format. You'll have to read headers and compression and bit depth, and decode all of that.

Have you considered getting some kind of image library like LeadTools?
Was This Post Helpful? 0
  • +
  • -

#3 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 13
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: vb.Net streaming bitmaps

Posted 22 May 2009 - 11:05 AM

That's what I was hoping someone could help me with, how to read the headers and pull the pixel data from the stream and such. There has to be a more robust way to access an image, because other programs can open the same image for editing, but my program wont even make it that far...

As for leadtools, it's a nice suggestion, but i'd rather not pay $400 for something that I can make (maybe) for free =\
Was This Post Helpful? 0
  • +
  • -

#4 bigtonyk  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 61
  • Joined: 17-May 09

Re: vb.Net streaming bitmaps

Posted 22 May 2009 - 11:24 AM

View Postthe_hangman, on 22 May, 2009 - 10:05 AM, said:

That's what I was hoping someone could help me with, how to read the headers and pull the pixel data from the stream and such. There has to be a more robust way to access an image, because other programs can open the same image for editing, but my program wont even make it that far...

As for leadtools, it's a nice suggestion, but i'd rather not pay $400 for something that I can make (maybe) for free =\


Gotcha.

TIFF - http://www.libtiff.org/
BMP - http://easybmp.sourceforge.net/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1