Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi friends, my application take snapshots using webcam and save them in a local folder. so i'm using following code to convert my Silverlight Image and send it through the Web Service. name of my web service is ImageService.

C#
ImageServiceSoapClient client = new ImageServiceSoapClient();

private void source_CaptureImageCompleted(object sender, CaptureImageCompletedEventArgs e)
        {            
            WriteableBitmap bmp = new WriteableBitmap(320, 240);
            bmp = e.Result;
            byte[] buffer = bmp.ToByteArray();            
                     
            client.SaveImageToLocalAsync(buffer, txtUserName.Text);            
        }



and this is my server side code..

C#
[WebMethod]
 public string SaveImageToLocal(byte[] buffer,string name)
 {

     try
     {
         Bitmap bmp = new Bitmap(320, 240);
         using (MemoryStream stream = new MemoryStream(buffer))
         {
             bmp = new Bitmap(stream);
             string saveString = GetFolder() + name + ".jpg";
             bmp.Save(saveString, System.Drawing.Imaging.ImageFormat.Jpeg);
         }

         return "Servers says : Saved..!!";
     }
     catch (Exception ex)
     {
         return "Server says : " + ex.Message;
     }
 }



so when i run this application, i'm getting an exception saying "Server says : Parameter is not valid"..

can anyone please tell me what's wrong with this code? i spent weeks to solve this problem. please back me up..!! thanks..
Posted
Comments
Sergey Alexandrovich Kryukov 3-Apr-13 1:08am    
Why? There is no such thing as ASP.NET bitmap. System.Drawing.Bitmap? But why?
—SA

1 solution

Please see my comment to the question.

There is no such thing as ASP.NET bitmap. You can use WPF bitmaps even in ASP.NET, why not? ASP.NET is a server-side technology, so, there is no .NET UI, and therefore you can use any graphics library.

[EDIT]

For the conversion, see, for example, this code sample:
http://snipplr.com/view/63090/[^].

—SA
 
Share this answer
 
v2
Comments
d_lucifer 3-Apr-13 2:08am    
sorry i didn't mean that. i just wanted to give an idea. that's why i wrote it that way, silverlight writablebitmap and asp.net bitmap. yeah i know WriteableBitmap inherits from System.Windows.Media.ImageSource and Bitmap inherits from System.Drawing.Image. but what do you mean? can i use WritableBitmap in ASP.Net ? or Bitmap in Silverlight? how??
Sergey Alexandrovich Kryukov 3-Apr-13 13:19pm    
Yes, you can. I would say, WPF, not Silverlight. Using this class, you can generate any thinkable bitmap and either send it in a file or in a stream of the HTTP response. This is all ASP.NET does.
If this is not clear, I'll explain in more detail, but you need to explain your ultimate purpose; what effect to you want to achieve?
Put it this way: with ASP.NET, anything you could do with System.Drawing.Bitmap, you can alternatively do with WPF bitmaps.
—SA
d_lucifer 3-Apr-13 16:06pm    
actually i don't know much about WPF and ASP.Net. anyway what i want to do is i need to take a snapshot of a person using the webcam and i want to save that image as jpg or png automatically to a local folder. that local folder should be in my asp.net website project because i'm going to compare that image with another image using EMGU CV. so that i can easily assign that jpg or png to a bitmap and work with my other functions. do you have any idea regarding my requirement?
Sergey Alexandrovich Kryukov 3-Apr-13 16:13pm    
Does EMGU require only System.Drawing.Bitmap? That could really be a reason to prefer this type, but why would you get WriteableBitmap in first place? If you get System.Drawing.Bitmap, you would not need WPF...
—SA
d_lucifer 4-Apr-13 0:32am    
exactly that's what i want to achieve. i want to get that snapshot as a bitmap. since silverlight doesn't support for System.Drawing.Imaging class, i have to use WriteableBitmap from System.Windows.Media.Imaging class. then i convert that WriteableBitmap to a byte array and send it to the web service. that web service will do the rest.

so can you just refer the above code and tell me what's wrong with it?

or if you know any other way to convert WriteableBitmap to a byte array properly and convert it back to Bitmap format, then please tell me how to do it..

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