0

我搜索了很多,但我得到了从Url或获取缩略图的样本Http,但我实际上需要从我自己的目录中获取图像sdcard的缩略图而不访问Android默认缩略图目录,那就是我需要获取图像的缩略图从 mnt/sdcard/myown/1.png

有人可以帮忙吗?

提前致谢。

4

2 回答 2

0
@Override
public void onCreate(Bundle savedInstanceState) {
    button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(onClickListener);
    image = (ImageView) findViewById(R.id.imageView1);

}

private OnClickListener onClickListener = new OnClickListener() {
    @Override
    public void onClick(final View v) {
        switch(v.getId()){
            case R.id.button1:
            String imagePath = Environment.getExternalStorageDirectory().toString() +"/myown/1.png";
            Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
            image.setImageBitmap(bitmap);
            break;
        }
    }
};

your layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/android" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Change Image" />

</LinearLayout>
于 2013-04-12T08:45:34.297 回答
0

Environment.getExternalStorageDirectory() 返回“/mnt/sdcard”

String imagePath = Environment.getExternalStorageDirectory().toString() + PATH_TO_IMAGE;
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
于 2013-04-12T07:57:47.853 回答