473,407 Members | 2,314 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,407 software developers and data experts.

Out of memory error while trying to assing memorystream object to a bitmap object

Hello all

Am trying to debug an application written by someone else. The issue is we get an "Out of Memory" when executing the following code

Expand|Select|Wrap|Line Numbers
  1. Dim mImages(1000) As Image
  2. dr = cmd.ExecuteReader()
  3.                 While dr.Read
  4.                     mName = CStr(dr.GetValue(0))
  5.                     mAccount = CStr(dr.GetValue(1))
  6.                     mLocation = CStr(dr.GetValue(2))
  7.                     mdate = FormatDateTime(dr.GetValue(3))
  8.                     Dim bytBlobData(dr.GetBytes(4, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
  9.                     dr.GetBytes(4, 0, bytBlobData, 0, bytBlobData.Length)
  10.                     Dim stmBlobData As New MemoryStream(bytBlobData) 
  11.                     Dim MyBitmap As New Bitmap(stmBlobData) <<== Error in this line
  12.  
  13.                     Dim objStream As New MemoryStream
  14.                     Dim myEncoder As Encoder
  15.                     Dim myEncoderParameter As EncoderParameter
  16.                     Dim myEncoderParameters As EncoderParameters
  17.                     Dim myImageCodecInfo As ImageCodecInfo = GetEncoderInfo("image/jpeg")
  18.                     myEncoder = Encoder.Transformation
  19.                     myEncoderParameters = New EncoderParameters(1)
  20.                     myEncoderParameter = New EncoderParameter(myEncoder, i)
  21.                     myEncoderParameters.Param(0) = myEncoderParameter
  22.                     MyBitmap.Save(objStream, myImageCodecInfo, myEncoderParameters)
  23.                     mImages(i) = Drawing.Image.FromStream(objStream)
  24.                     Me.ilsImages.Images.Add(i, System.Drawing.Image.FromStream(objStream))
  25.                     Me.ToolStrip1.Items.Add(System.Drawing.Image.FromStream(objStream))
  26.                     Me.ToolStrip1.Items(i).Text = FormatDateTime(mdate, DateFormat.ShortDate)
  27.                     stmBlobData.Close()
  28.                     'objStream.Close()
  29.                     MyBitmap.Dispose()
  30.                     i = i + 1
  31.                 End While
  32.  
This happens mostly when the image is big. Can someone help me how to handle this issue? I tried searching everywhere but in vain.
(ilsImages is ImageList)

Thanks
AC
Oct 22 '10 #1
0 917

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

Similar topics

8
by: Benjamin Scott | last post by:
Hello. I attempted to build a compound dictionary: len(Lst)=1000 len(nuerLst)=250 len(nuestLst)=500 Dict={}
1
by: someone | last post by:
Please bear with me, since I'm an ASP guy, and not a .NET guy. On my site, I dynamically resize/resample images so they're not too large. GetThumbnail resulted in very poor quality, so I create a...
2
by: Raed Sawalha | last post by:
I have a Bitmap Object and I need to return it as array of bytes is it possible
3
by: RD | last post by:
I have a VBV.NET application that runs on a timer to do a job at one hour intervals. Basically the sequence is as follows the timer event fires 1- the timer get turned off 2- the code then...
6
by: rlcavebmg | last post by:
I am new to Web Services and .NET development, and I have a question. I am writing a service that will create a bitmap image and return it to the client. First, I wrote a method that looked like...
15
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
1
by: =?Utf-8?B?ZWRkeWN0YW0=?= | last post by:
When creating a Bitmap object in C# with Bitmap temp = new Bitmap("(filename here)"; What is put into memory? Is it just the bitmap info header or is the entire bitmap loaded into memory? If it...
2
by: Nagu | last post by:
I am trying to save a dictionary of size 65000X50 to a local file and I get the memory error problem. How do I go about resolving this? Is there way to partition the pickle object and combine...
0
by: Nagu | last post by:
I am trying to save a dictionary of size 65000X50 to a local file and I get the memory error problem. How do I go about resolving this? Is there way to partition the pickle object and combine...
5
by: mnflint | last post by:
I am having a problem resizing multiple images at a time. The images are 13200x20394 1bpp png images. In my sample set of 10 I can proess 4 before I get an "Out of memory" error. I am running...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.