简体   繁体   English

将writeablebitmap编码为jpeg,然后编码为base64string

[英]Encode writeablebitmap into jpeg then into base64string

I am building a surface-rt app that takes a picture which results into a stream and a WriteableBitmap as this example shows I then encode the stream into a Base64String and pass it to a WebApi service where I store it in a server. 我正在构建一个Surface-rt应用程序,该应用程序拍摄一张图片并将其生成为流和WriteableBitmap, 如本示例所示 ,然后我将该流编码为Base64String并将其传递给WebApi服务,并将其存储在服务器中。

The same sample page suggests to encode the image into jpeg before saving as the resulting file will be quite large, now my question is can I/Should I encode the stream/writeableBitMap before enconding it into a base64string to reduce the traffic to the webapi service. 相同的示例页面建议在保存之前将图像编码为jpeg,因为结果文件将非常大,现在我的问题是我是否可以在将stream / writeableBitMap编码为base64string之前对其进行编码,以减少对webapi服务的访问量。

Disclaimer: I have very little experience handling images, thanks in advance. 免责声明:我对图像处理的经验很少,谢谢。

The method described in the link you shared seems like the right approach for compressing a WriteableBitmap . 您共享的链接中描述的方法似乎是压缩WriteableBitmap的正确方法。 You do want to compress the captured image to make it smaller. 您确实想压缩捕获的图像以使其更小。 The only remaining part is encoding it as Base64 which you can do using Convert.ToBase64String() . 剩下的唯一部分是将其编码为Base64,您可以使用Convert.ToBase64String()编码。 The one thing I would consider is to use something like BackgroundUploader.CreateUploadFromStreamAsync() to upload the stream. 我会考虑的一件事是使用BackgroundUploader.CreateUploadFromStreamAsync()类的东西来上传流。 In that case you might not want to do the Base64 encoding part on the client side, but perhaps do it on the server instead. 在那种情况下,您可能不想在客户端上执行Base64编码部分,而是可能在服务器上执行。 I'm not an http expert, but Base64 makes your data larger and I'd suspect there might be faster ways to upload bits these days than using Base64 and also your Base64-encoded string might end up being Base64-encoded twice - making the transmitted data larger yet. 我不是http专家,但是Base64使您的数据更大,并且我怀疑这些天可能比使用Base64更快地上传位,而且您的Base64编码的字符串可能最终会被Base64编码两次-使传输的数据更大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM