简体   繁体   English

Android:MediaStore.Images.Media.EXTERNAL_CONTENT_URI…以全尺寸显示图片吗?

[英]Android: MediaStore.Images.Media.EXTERNAL_CONTENT_URI … show pictures in full size?

I guess this question has been asked before, but I can't seem to find a proper answer/solution. 我想这个问题以前曾被问过,但我似乎找不到合适的答案/解决方案。

Have a note-taking app, which allows to take pictures. 有一个记笔记的应用程序,可以拍照。 For that I start an intent, that starts up the built-in camera-app. 为此,我启动了一个意图,即启动了内置的camera-app。 So far so good. 到现在为止还挺好。

But when I show that image in my app, it's in a much smaller format :( 但是,当我在应用程序中显示该图像时,它的格式要小得多:(

The funny/weird thing is, that the camera-app did take a full-resolution picture! 有趣/奇怪的是,相机应用确实拍摄了全分辨率图片! But for some reason I can't get the full version to show in my app??? 但是由于某些原因,我无法在我的应用程序中显示完整版本???

So, when I use the standard Android Gallery app, and go to that picture, it is very obvious that it's full size (I can zoom in and see details I really can't see when I zoom in, in my own app). 因此,当我使用标准的Android Gallery应用程序并转到该图片时,很明显它是完整尺寸的(我可以在自己的应用程序中放大并查看我放大时实际上看不到的细节)。 Also, the dimensions are really those of the original picture, taken with the 5MP camera. 另外,尺寸实际上是使用5MP相机拍摄的原始尺寸。

In my app, they are very small. 在我的应用中,它们很小。 My phone has Android 2.2, but the same happens on my emulator (Android 2.1). 我的手机装有Android 2.2,但在模拟器(Android 2.1)上也是如此。

How should I retrieve the pictures in my app??? 我应该如何在我的应用程序中检索图片??? Tried a couple of ways, but none works :( Don't need a complete example (allthough that's very welcome), just a few clues are enough to search for myself. 尝试了几种方法,但没有用:(不需要完整的示例(尽管这很受欢迎),仅需提供一些线索即可进行自我搜索。

Tx in advance!! 提前发送!

Greetingz, Koen< 科恩Greetingz <

Very weird, I found the solution/answer by looking at the _ID-values that were being inserted in my own database. 很奇怪,我通过查看插入到我自己的数据库中的_ID值找到了解决方案/答案。 First I noticed that when I selected an existing image (via the build-in Android Gallery), I did get the full size image. 首先,我注意到当我选择一个现有图像(通过内置的Android Gallery)时,我确实获得了全尺寸图像。

When I first took a picture, I got a scaled image. 当我第一次拍照时,我得到了缩放的图像。 So where was the difference. 那么区别在哪里。 Apparantly at the location where the _ID of the picture got stored in my database. 大约在图片的_ID存储在我的数据库中的位置。 In my case, and probably most cases, this happens in the onActivityResult procedure. 就我而言,也许在大多数情况下,这发生在onActivityResult过程中。

First take a look at what I initially had: 首先看看我最初拥有的东西:

if(requestCode == REQUEST_CAMERA && resultCode == RESULT_OK){
        String timestamp = Long.toString(System.currentTimeMillis());

        // get the picture
        mPicture = (Bitmap)result.getExtras().get("data");

        //save image to gallery
        String pictureUrl = MediaStore.Images.Media.insertImage(getContentResolver(), mPicture, getResources().getString(R.string.app_name_short), timestamp);
        insertPictureAttachment(mRowId.intValue(), Integer.parseInt(Uri.parse(pictureUrl).getLastPathSegment()));

The "insertPictureAttachment"-method does the actual inserting into the database. “ insertPictureAttachment”方法将实际插入数据库。

Looking backwards, this was a bit weird anyway ... make a picture, so I could make an URI of it, and then get the last path segment (which is the _ID), so I could insert that into my database. 向后看,无论如何还是有点奇怪的……制作一张图片,所以我可以为其制作一个URI,然后获取最后一个路径段(即_ID),因此可以将其插入数据库中。

Eventually, it turns out that I can replace the above code with just one line: 最终,事实证明我可以只用一行替换上面的代码:

insertPictureAttachment(mRowId.intValue(), Integer.parseInt(result.getData().getLastPathSegment()));

Much shorter, and actually makes more sense ... rather than getting the info from result.getExtras().get("data"), I get my info from result.getData(), which gives the _ID of the original, full-size image. 更短,而且实际上更有意义...而不是从result.getExtras()。get(“ data”)获取信息,我从result.getData()获取我的信息,该信息提供了完整的原始_ID尺寸的图像。

I will do some further research on this though, cause it's not clear to me yet why I actually don't have to call MediaStore.Images.Media.insertImage(...) ... maybe I will have to if I want specific features (like a custom file location or something like that). 不过,我将对此做一些进一步的研究,因为目前尚不清楚为什么我实际上不必调用MediaStore.Images.Media.insertImage(...)...如果我想具体说明,也许我必须这样做功能(例如自定义文件位置等)。

Greetingz, Koen< 科恩Greetingz <

暂无
暂无

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

相关问题 Android 9 (Pie) ContentResolver 查询 MediaStore.Images.Media.EXTERNAL_CONTENT_URI 在 api 28 上返回 null - Android 9 (Pie) ContentResolver query MediaStore.Images.Media.EXTERNAL_CONTENT_URI returns null on api 28 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI报告为未知URI - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI reported as Unknown URI 查询 MediaStore.Images.Media ,如何同时查询 EXTERNAL_CONTENT_URI 和 INTERNAL_CONTENT_URI? - Querying MediaStore.Images.Media , how do I query both on EXTERNAL_CONTENT_URI and INTERNAL_CONTENT_URI? 在Android中的MediaStore.Audio.Media.EXTERNAL_CONTENT_URI中插入音频文件时出现问题 - problem while inserting audio file in MediaStore.Audio.Media.EXTERNAL_CONTENT_URI in android MediaStore.Audio.Media.EXTERNAL_CONTENT_URI返回一个空游标 - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI return an empty cursor ContentResolver 插入 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI 错误 - ContentResolver insert MediaStore.Audio.Media.EXTERNAL_CONTENT_URI error MediaStore.Images.Media.INTERNAL_CONTENT_URI返回空游标 - MediaStore.Images.Media.INTERNAL_CONTENT_URI returns empty cursor 拒绝权限:阅读com.android.providers.media.MediaProvider uri content:// media / external / images / media / 38 - Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/38 在查询`MediaStore.Audio.Media.EXTERNAL_CONTENT_URI`之前,有没有办法强制系统媒体重新扫描? - Is there any way to force a system media rescan before querying `MediaStore.Audio.Media.EXTERNAL_CONTENT_URI`? 我的设备上的查询问题(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,null,null,null,null) - problem with query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null) on my device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM