【发布时间】:2014-01-16 09:39:46
【问题描述】:
创建自己的相机,因为我需要专注于拍照。相机按预期工作得很好。在活动之间传递URI。
我在 Next Screen 中有 ImageView,我用它来设置图像
imgView.setImageURI(absPathUri);
检查absPathUri 不为空。 ImagView 仍然是空白,没有图片。在调试模式下执行相同操作会将图片带入 ImageView。
谁能告诉我哪里做错了?
同样发送广播重新扫描设备,但跟随 sn-p 仍然没有成功。
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(absPathUri.getPath());
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
使用下面的sn-p生成absPathUri
if (Environment.MEDIA_MOUNTED.equals(state))
{
imageDirectory = new File(AppConstants.IMAGE_DIRECTORY_PATH);
}
else
{
imageDirectory = new File(AppConstants.IMAGE_DIRECTORY_PATH_DATA);
}
imageDirectory.mkdirs();
File tempFile = new File(imageDirectory, getVideoName()+ jpg);
Uri outputFileUri = Uri.fromFile( tempFile );
absPathUri = outputFileUri;
public static String getVideoName()
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
try {
name = sdf.format(new Date(System.currentTimeMillis()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return name;
}
下面是我用来在 xml 中显示 ImageView 的布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/bg"
>
<ImageView
android:id="@+id/picView"
android:layout_above="@+id/buttonPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="@drawable/accounts_glyph_password_default"
/>
<LinearLayout
android:id="@id/buttonPanel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onDiscard"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:text="@string/save"
android:onClick="onSave"
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
【问题讨论】:
-
你能告诉我你是如何创建对象 absPathUri
-
@gnuanu :根据您的要求编辑了 OP。但是为什么它在调试模式下工作。
-
根据文档,不建议使用 setImageURI 读取大图像,因为所有处理都发生在 UI 线程(读取/解码/渲染)developer.android.com/reference/android/widget/…
-
@gnuanu
Bitmap bm=null; bm = BitmapFactory.decodeFile(absPathUri.getPath()); imgView.setImageBitmap(bm);尝试了这些仍然没有图像显示
标签: android uri android-imageview android-image