Bitmap upload from ppc to web server

W

willis

Hi, guys

I have spent the whole week to look for how to upload image from pocket
pc to web server, but still couldn't find a solution. Can anyone please
help?

My situation is
I download a GIF file from web server and display in a picturebox on a
I-mate ppc(This part is done), then the user will add some signs or
draw the notes or icons in the image, finally I would like to upload
this image back to web server (doesn't matter by HTTP, SOCKET, FTP,web
services, DIME, as long as it can work)

My idea is
the GIF file size is 512 x 512, when I tried to save the picturebox
image as a physical bitmap file in the ppc(using the MS Save Bitmap
example,http://www.microsoft.com/downloads/...82-D87D-43C6-A984-8C625387B198&displaylang=en),
it takes more then 3 minutes to finish, and the size is about 1.6MB.
So, I'm thinking maybe I could directly send the Bitmap
object(picturebox.image) to the web server, instead of saving as a
local file.

I tried to upload the Bitmap object to web server? I couldn't find a
way to serizalize it to a stream or byte array.
Then I tried to use the DIME and WSE2 to send the image as a DIME
attachment, but don't know how to do it.

Please correct me if I'm not in the right track, or please give me any
idea how to upload the Bitmap object to the server.

Thanks a lot!

Willis
 
G

Guest

Search the archives. Alex Feinman has posted a link to a sample. A search
string like 'Feinman File Upload' works well.

-Chris
 
C

chris-s

Try the following, works for us, sorry about the 'indenting'!!

Chris


public bool UploadFileBinary(string localFile, string uploadUrl)
{
BinaryReader rdr = null;
byte[] data = null;
try
{
rdr = new BinaryReader(File.OpenRead(localFile));
data = rdr.ReadBytes((int)rdr.BaseStream.Length);
}
catch(IOException ioex)
{
System.Windows.Forms.MessageBox.Show(ioex.ToString(), "File Open
Failed");
return false;
}


// Make sure the url is properly escaped. Uri class takes care of
that
Uri uri = new Uri(uploadUrl);


HttpWebRequest req = HttpWebRequest.Create(uri) as HttpWebRequest;
req.Method = "PUT";

// For large files (> 50KB) you may want to uncomment the next line
//req.SendChunked = true;
req.ContentLength = data.Length;
Stream reqStream = null;
try
{
reqStream = req.GetRequestStream();
}
catch(WebException we)
{
System.Windows.Forms.MessageBox.Show("Error!
\n\r\n\r"+we.ToString());
return false;
}
reqStream.Write(data, 0, data.Length);
reqStream.Close();
HttpWebResponse resp = null;
try
{
resp = req.GetResponse() as HttpWebResponse;
}
catch (WebException we2)
{
System.Windows.Forms.MessageBox.Show("Error!
\n\r\n\r"+we2.ToString());

return false;
}
HttpStatusCode code = resp.StatusCode;
rdr.Close();
//System.Windows.Forms.MessageBox.Show("Request succeeded: " +
code.ToString() );
return true;
}
 
G

Guest

First of all you want to compress your images before you upload them to the
server, I think the reason for doing this is obvious. I personaly prefer
Exceed Zip product (http://www.xceedsoft.com/products/ZipNetCF/index.aspx)
for compression. Opon compressing the image file, you will obtain a tream
that can be uploaded to a server as a byte array (using a web service) .
 
W

Willis

Thank you so much for all of your help!

I got flu today and really don't have energy to try it tonight, will
let you guys know tomorrow.

However, all the solutions mentioned have to convert the Bitmap Object
into a physical file before uploading. In my case, it takes more than
3 minutes to save the image as a Bitmap file on the PDA, and I don't
think it's a good way to do it. Could anyone please point out a better
way to deal with such situation? I'm really appreciated for that!

Cheers

Willis
 
G

Guest

The Exceed's solution should allow you to work with your images in memory
(leveraging MemoryStream or equivalent), just make sure you have enough
memory on your device. You will also want to pay extra attention with your
application's memory management as it sounds like you will be using a lot of
it. Look at the Garbage collection documentation to see how you can leverage
it or simply be very disciplined in your code by destroying reference type
variables as soon as you are done using them.

Thanks,

Yves.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top