Click here to Skip to main content
15,125,104 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi ,
I am converting bytearray[] to System.drawing.image this is working fine. But how can i save this image into local directory.

if I give _objImage.Save(path,_objImage.RawFormat); this give an error.

"Error in GDI+"
Give me a solution.



Sorry I can't understand.
This is my code to convert base64 code into image.
C#
public static Image Base64ToImage(string base64String)
{
 
byte[] imageBytes = Convert.FromBase64String(base64String);
Image image;
using (MemoryStream inStream = new MemoryStream())
{
inStream.Write(imageBytes, 0, imageBytes.Length);
 
image = Bitmap.FromStream(inStream);
// image.Save(inStream, System.Drawing.Imaging.ImageFormat.Png);
image.Save(inStream, image.RawFormat);
}

return image;
}



Now i want save this image into local directory how can i do this.

if i use
C#
Image _ObjImage = Base64ToImage(Img);
DirectoryInfo dir = new DirectoryInfo(PATH + @"EndUsersUI\UploadedPic\" + id +"\\");
_ObjImage.Save(dir + smallpicname, _ObjImage.RawFormat);

This is giving me an error.
Posted
Updated 3-Sep-12 23:43pm
v3

Now you have JPG file in server. If you want to save in client machine then you have to transmit that. Here is code :-

C#
Response.ContentType = "image/jpeg";
        Response.AppendHeader("Content-Disposition", "attachment; filename=Image.jpg");
        Response.TransmitFile(Server.MapPath("Image.jpg"));
        Response.End();
   
Comments
Prasad_Kulkarni 4-Sep-12 7:57am
   
5'ed :D
   
Comments
Prasad_Kulkarni 4-Sep-12 7:57am
   
5'ed :D
Anuja Pawar Indore 4-Sep-12 8:06am
   
Thanks Prasad :)
Finally i have solved.
and the answer is Convert ByteArray[] to Bitmap not in Image after that u can easily store your image into any folder or u can crop this through resize method of Drawing class.
   
Sorry I can't understand.
This is my code to convert base64 code into image.

C#
public static Image Base64ToImage(string base64String)
{

    byte[] imageBytes = Convert.FromBase64String(base64String);
    Image image;
    using (MemoryStream inStream = new MemoryStream())
    {
        inStream.Write(imageBytes, 0, imageBytes.Length);

        image = Bitmap.FromStream(inStream);
       // image.Save(inStream, System.Drawing.Imaging.ImageFormat.Png);
        image.Save(inStream, image.RawFormat);
    }

    return image;
}



Now i want save this image into local directory how can i do this.

if i use
C#
Image _ObjImage = Base64ToImage(Img);
DirectoryInfo dir = new DirectoryInfo(PATH + @"EndUsersUI\UploadedPic\" + id +"\\");
_ObjImage.Save(dir + smallpicname, _ObjImage.RawFormat);


This is giving me an error.
   
v2
Comments
_Amy 4-Sep-12 5:35am
   
You should Improve your answer. You should not paste your trial in your solution box.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900