开发者

Save image without dialog in Silverlight

My application will be a drawing canvas and user can click the save but开发者_如何学JAVAton. The image will then be saved inside the server somewhere where the xap file lies.

I don't think i can use dialog. How can I save an image?

I've considered converting images to a stream and then write it to the path. Is it the right way?

EDIT

I tried converting the image to stream and write it, but i encounter access permission denied error. So i'm using Webclient now. Everything works fine and there's no error, however the image just don't overwrite even if there's no error. Following are my codes, do enlighten me. Thanks!

//Code to create WriteableBitnap with InkPresenter named "strokeTest"//

WriteableBitmap wb = new WriteableBitmap(strokeTest, null);

//End...Code to create WriteableBitnap with InkPresenter named "strokeTest"//


//code used to convert WrtiteableBitmap to byte array//
int w = wb.PixelWidth;
int h = wb.PixelHeight;
int[] p = wb.Pixels;
int len = p.Length;
byte[] result = new byte[4 * w * h];

// Copy pixels to buffer
for (int i = 0, j = 0; i < len; i++, j += 4)
{
    int color = p[i];
    result[j + 0] = (byte)(color >> 24); // A
    result[j + 1] = (byte)(color >> 16); // R
    result[j + 2] = (byte)(color >> 8);  // G
    result[j + 3] = (byte)(color);       // B
 }
 //End...code used to convert WrtiteableBitmap to byte array//


 //Code to overwrite the file using Webclient//
 WebClient wc = new WebClient();
 Uri u = new Uri("/test/brush_shape.png", UriKind.Relative);
 wc.OpenWriteAsync(u, null, result);
 //End...Code to overwrite the file using Webclient//


Why you haven't use an image control and benefits Source property on this control?then you can make a bytes array of your image and send to server

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜