Monodroid 相机/图像视图示例
有人可以发布一个示例,说明如何使用相机、捕获图像、在图像视图中预览图像、将图像压缩为 jpg 并将字节上传到远程服务器吗?我能找到的最接近的如下。我们有相机和图像捕获,但我们需要知道如何预览、将 jpg 压缩/调整为 640/480px 和大约 120kb 大小,然后将字节上传到远程服务器。感谢大家的帮助。 http://android-coding.blogspot.com/2010/12 /intent-of-mediastoreactionimagecapture.html
Can someone post an example of how to use the camera, capture the image, preview the image in an image view, compress the image in jpg and upload the bytes to a remote server? The closest I have been able to find is below. We have the camera, and image capture but we need to know how to preview, compress/resize jpg to 640/480px and around 120kb size then upload bytes to a remote server. Thanks to all of you for your help.
http://android-coding.blogspot.com/2010/12/intent-of-mediastoreactionimagecapture.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看您的代码,我发现有些事情是错误的:
-[用于相机功能]-
您正在检索字符串值变量以获取完整图像的 URI?只需将从第一点中的代码中获取的 uri 保存为属性(比方说活动类中的“myPhotoURI”)。在处理相机意图结果的 OnActivityResult 函数中,只需回忆该 URI 并按如下方式使用它(是的,您没看错;我什至没有使用数据意图,只是记住了 uri):
Bitmap imageFromCam = MediaStore.Images.Media.GetBitmap(this.ContentResolver, Android.Net.Uri.Parse(myPhotoURI));
要从图库中获取图像,只需使用 SelectImageFromStorage() 函数 从这个问题的答案并在 OnActivityResult 检查中检索所选图像的 URI,只需使用:
Android.Net.Uri selectedImageUri = data.ToURI();
这对我来说就像一个魅力。
-[将数据发送到 Web 服务]-
假设您正在使用 WCF 或 Web 服务,并且希望以字节数组的形式接收图像数据; 此问题的批准答案给出了一个很好的例子,说明如何将图像转换为字节数组(无论如何,这正是 WCF Web 服务想要的),
我认为这些方向将帮助您前进。
Looking at your code there are some things i notice to be wrong:
-[ for the camera functionality ]-
You are retrieving a string value variable to get the URI to the full image? Just save the uri you get from the code in my first point as a property (let's say "myPhotoURI" in the activity class. In the OnActivityResult function that handles your camera intent result just recall that URI and use it as following (Yes, you're seeing it right; i'm not even using the data intent for this just the remembered uri):
Bitmap imageFromCam = MediaStore.Images.Media.GetBitmap(this.ContentResolver, Android.Net.Uri.Parse(myPhotoURI));
To grab an image from the gallery just use the SelectImageFromStorage() function from this question's answer and retrieve the URI of the chosen image in the OnActivityResult check just use:
Android.Net.Uri selectedImageUri = data.ToURI();
That's what worked like a charm for me.
-[sending the data to a webservice ]-
Assuming you're using a WCF or webservice that'll want to receive the image data as a byte array; the approved answer to this question gives a nice example of how to convert your image to an byte array (which is what a WCF webservice wants, anyway)
I think that these directions will get you going.
这是迄今为止最接近的示例...当使用额外输出时,这会返回空数据。仍在尝试访问完整图像/照片而不是缩略图。
here is the closest example to date... this brings back Null data when the extra output is used. Still trying to get access to the full image/photo and not a thumbnail.