Out of Memory Error using C#.net

Posted by Naraayanan under C# on 6/15/2012 | Points: 10 | Views : 2717 | Status : [Member] | Replies : 1
Hi,
I copied a Image file(like jpeg,tif,bmp) from one location to another location. But I got "Out of Memory Error" .So How can i solve this problem?

I am using below code:
Stream buffer;
StreamReader srImage = new StreamReader(InputPath);
buffer = srImage.BaseStream;
Bitmap bmImage = new Bitmap(buffer);
StreamWriter srSettings = new StreamWriter(OutputPath);
srSettings.Write(bmImage);


It works fine. But File length is greater than 1MB.It doesn't work.So How can i solve this?Please do needful.

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/



Responses

Posted by: Ashyour on: 6/21/2012 [Member] Starter | Points: 25

Up
0
Down
Why are you loading large image in the memory?
you can use File.copy() to copy image to other location.
or If you need to manipulate Bitmap then you can use the constructor Bitmap(filename ) to create Bitmap object and after manipulation use Bitmapobj.save(targetfilename) to save it to other location

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response