@Brandon Boone you lockbits but i dont see you unlock bits?
maybe clean up, in a finally statement?
finally
{
b.UnlockBits(bData);
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
So I am getting this Exception: "Exception of type 'System.OutOfMemoryException' was thrown." but only after I open like 3 different pictures are the same time. This seem weird to me. I have opened way more than that with Adobe Illustrator. anyhow, I have a try catch and after It fails, I try to openned a new picture and it will work well for another 3 or 4 pictures. I have not idea why.
Here is my Code:
static private double[,] ImageToByteArray(Bitmap _image, int height, int width)
{
using (Bitmap b = new Bitmap(_image))
{
BitmapData bData = b.LockBits(new Rectangle(0, 0, _image.Width, _image.Height), ImageLockMode.ReadWrite, b.PixelFormat);
/* GetBitsPerPixel just does a switch on the PixelFormat and returns the number */
byte BitsPerPixel = GetBitsPerPixel(bData.PixelFormat);
/*the size of the image in bytes */
int size = bData.Stride * bData.Height;
int Stride = bData.Stride;
/*Allocate buffer for image*/
byte[] data = new byte[size];
double[,] returndata = new double[height, width];
/*This overload copies data of /size/ into /data/ from location specified (/Scan0/)*/
Marshal.Copy(bData.Scan0, data, 0, size);
int i = 0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
double magnitude = ((0.0722D * data[i]) + (0.7152D * data[i + 1]) + (0.2126D * data[i + 2]));
returndata[y, x] = magnitude;
i += BitsPerPixel / 8;
}
}
_image.Dispose();
data = null;
return returndata;
}
}
it fails at double[,] returndata = new double[height, width]; and I do not know why
I checked Task Manager and the program got up to 2,651.8.
I should be about to open multiple pictures at a time correct?
I can with Photos.
@Brandon Boone you lockbits but i dont see you unlock bits?
maybe clean up, in a finally statement?
finally
{
b.UnlockBits(bData);
}
All,
I believe I fixed it by changing the program to a x64
Mabye one pixel four bytes?