image upload server side code using .net C# problem

All your problems with Audio, Video and Images.

image upload server side code using .net C# problem

Postby wangqaa » Tue Dec 08, 2009 5:05 am

I try to get the post stream from android client side.
But get error from server side .
System.ArgumentException: invalide parameter at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) at System.Drawing.Image.FromStream(Stream stream)

server side code C#
page_load
{

Stream sin = Page.Request.InputStream;

System.Drawing.Image img = System.Drawing.Bitmap.FromStream(sin);

Bitmap bmp = new Bitmap(img);

MemoryStream bmpStream = new MemoryStream();

bmp.Save(bmpStream, System.Drawing.Imaging.ImageFormat.Jpeg);

FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("b.jpg"), FileMode.Create);
bmpStream.WriteTo(fs);
bmpStream.Close();
fs.Close();
bmpStream.Dispose();
fs.Dispose();
}

Does anyone can help me figure out the problem. It confused me for weeks...><~

thanks~
wangqaa
Freshman
Freshman
 
Posts: 4
Joined: Thu Nov 19, 2009 7:16 am
Location: Taiwan

Top

Postby qlimax » Wed Dec 09, 2009 1:04 am

hi,

have you tried this to obtain the image?

ImageConverter imageConverter = new System.Drawing.ImageConverter();
Image image = imageConverter.ConvertFrom(sin) as Image;

just to try...

bye :)
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby wangqaa » Wed Dec 09, 2009 7:59 am

Hi,

thanks for reply~

I tried it.

imageConverter.ConvertFrom()

not support inputstream parameter

error :cry:

I will keep on trying...
wangqaa
Freshman
Freshman
 
Posts: 4
Joined: Thu Nov 19, 2009 7:16 am
Location: Taiwan

Postby wangqaa » Thu Dec 10, 2009 2:29 am

code below is work.

get the post stream and transfer to image then save at sever side.(also can save image byte[] in database)
-------
Stream sin = Page.Request.InputStream;
byte[] strArr = StreamToBytes(sin);
MemoryStream bmpStream = new MemoryStream(strArr,true);
bmpStream.Read(strArr, 0, strArr.Length);
bmpStream.Position = 0;
System.Drawing.Image image = System.Drawing.Image.FromStream(bmpStream);
FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("b.jpg"), FileMode.Create);
bmpStream.WriteTo(fs);
bmpStream.Close();
fs.Close();
bmpStream.Dispose();
fs.Dispose();
-------
wangqaa
Freshman
Freshman
 
Posts: 4
Joined: Thu Nov 19, 2009 7:16 am
Location: Taiwan

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 5 guests