机器人 - 图片选择器,错误的图像 [英] Android - Image Picker, Wrong Image

查看:179
本文介绍了机器人 - 图片选择器,错误的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始对摄像的要求:

 意向意图=新的意图();
intent.setType(图像/ *);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(意向,选择),PHOTO_GALLERY);
 

和获取数据传回在 onActivityResult

 如果(结果code == Activity.RESULT_OK和放大器;&安培;请求code == PHOTO_GALLERY)
{
  U.log(data.getData());
  位图BM = ... //从内置的getData()乌里
  this.postImage preview.setImageBitmap(BM);
}
 

当我启动的意图,我看到一些文件夹,如 SD卡投递箱 MyCameraApp ,等等。

如果我选择从 SD卡的图片,当我加载了preVIEW,这是完全错误的图像。在其他文件夹似乎并没有被给我这个问题。

有谁知道为什么它会让我选择一个图像,然后给我的URI,另一个?

编辑:下面是一些exampled记录的getData() S:

好:

内容://com.google.android.gallery3d.provider/picasa/item/5668377679792530210

为:

内容://媒体/外部/图片/媒体/ 28

编辑:我仍然有问题,从画廊的SD卡文件夹采摘时

下面是我在做什么在onActivityResult多一点的扩展:

  //光标
乌里selectedImage = data.getData();

的String [] filePathColumn = {MediaStore.Images.Media.DATA};

光标光标= mContext.getContentResolver()查询(selectedImage,filePathColumn,NULL,NULL,NULL);
cursor.moveToFirst();

INT参数:columnIndex = cursor.getColumnIndex(filePathColumn [0]);
字符串文件路径= cursor.getString(参数:columnIndex);
cursor.close();

//光标:/mnt/sdcard/Pic.jpg:/mnt/sdcard/Pic.jpg
U.log(光标:+文件路径+:+ Uri.parse(文件路径));

// 定期

//常规:内容://媒体/外部/图片/媒体/ 28:内容://媒体/外部/图片/媒体/ 28
U.log(常规+ data.getDataString()+:+ Uri.parse(data.getDataString()));

//常规2:内容://媒体/外部/图片/媒体/ 28:内容://媒体/外部/图片/媒体/ 28
U.log(普通2:+ data.getData()+:+ data.getData());


mPostImage preview.setImageBitmap(BitmapFactory.de codeFILE(文件路径));
mPostImage preview.setVisibility(View.VISIBLE);
 

他们还设置了错误的图像。如果我走进画廊,长preSS的图像,并查看其详细信息,我得到:

 标题:PIC
时间:2012年5月2日
宽度:720
高度:1280
方向:0
文件大小:757KB
制造商:ABSO相机
型号:启发4G
路径:/mnt/sdcard/Pic.jpg
 

所以,画廊是告诉我的路径是一样的挑动作,而画廊是正确的渲染它。那么,为什么在地球上岂不是渲染,如果我从onActivityResult设置呢?

此外,这是在code,我现在使用火的意图:

 私人无效selectPhoto()
{
  意向意图=新的意图(Intent.ACTION_GET_CONTENT);
  intent.setType(图像/ *);
  ((活动)mContext).startActivityForResult(Intent.createChooser(意向,选择图片),PHOTO_GALLERY);
}
 

解决方案

有时候在画廊的应用程序的缩略图,可以过时,显示缩略图,不同的图像。当图像的ID重复使用,例如,当一个图像被删除,并使用相同的id一个新添加会发生这种情况。

管理应用程序>图库>清除数据可以解决这个问题呢。

I am starting a request for an image pick:

Intent intent = new Intent();
intent.setType( "image/*" );
intent.setAction( Intent.ACTION_GET_CONTENT );
startActivityForResult( Intent.createChooser( intent, "Choose"), PHOTO_GALLERY );

And getting the data back out in onActivityResult:

if( resultCode == Activity.RESULT_OK && requestCode == PHOTO_GALLERY )
{
  U.log( data.getData() );
  Bitmap bm = ... // built from the getData() Uri
  this.postImagePreview.setImageBitmap( bm );
}

When I launch the Intent, I see some folders, such as sdcard, Drop Box, MyCameraApp, and so on.

If I chose a picture from sdcard, when I load the preview, it is the completely wrong image. The other folders don't seem to be giving me this problem.

Does anyone know why it'd let me pick one image, then give me the Uri for another?

EDIT: Here are some exampled logged getData()s:

Good:

content://com.google.android.gallery3d.provider/picasa/item/5668377679792530210

Bad:

content://media/external/images/media/28

EDIT: I'm still having issues, when picking from the sdcard folder of gallery.

Here is a bit more expansion of what I'm doing in onActivityResult:

// cursor
Uri selectedImage = data.getData();

String[] filePathColumn = { MediaStore.Images.Media.DATA };

Cursor cursor = mContext.getContentResolver().query( selectedImage, filePathColumn, null, null, null );
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex( filePathColumn[0] );
String filePath = cursor.getString( columnIndex );
cursor.close();

// Cursor: /mnt/sdcard/Pic.jpg : /mnt/sdcard/Pic.jpg
U.log( "Cursor: " + filePath + " : " + Uri.parse( filePath ) );

// "regular" 

// Regular: content://media/external/images/media/28 : content://media/external/images/media/28
U.log( "Regular: " + data.getDataString() + " : " + Uri.parse( data.getDataString() ) );

// Regular 2: content://media/external/images/media/28 : content://media/external/images/media/28
U.log( "Regular 2: " + data.getData() + " : " + data.getData() );


mPostImagePreview.setImageBitmap( BitmapFactory.decodeFile( filePath ) );
mPostImagePreview.setVisibility( View.VISIBLE );

They still set the wrong image. If I go into the Gallery, long press the image, and view its details I get:

TItle: Pic
Time: May 2, 2012
Width: 720
Height: 1280
Orientation: 0
File size: 757KB
Maker: Abso Camera
Model: Inspire 4G
Path: /mnt/sdcard/Pic.jpg

So, the Gallery is telling me the path is the same as the pick action, and the Gallery is rendering it correctly. So why on earth is it not rendering if I set it from onActivityResult?

Also, this is the code I'm using to fire the Intent now:

private void selectPhoto()
{
  Intent intent = new Intent( Intent.ACTION_GET_CONTENT );
  intent.setType( "image/*" );
  ( ( Activity )mContext ).startActivityForResult( Intent.createChooser( intent, "Select Picture" ), PHOTO_GALLERY );
}

解决方案

Sometimes the thumbnails in the gallery app can be outdated and show thumbnails for a different image. This can happen when the image ids are reused, for example when an image gets deleted and a new one is added using the same id.

Manage Apps > Gallery > Clear Data can fix this problem then.

这篇关于机器人 - 图片选择器,错误的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆