-1

此代码从 android 的 DRAWABLE 文件夹中读取图像:

import android.widget.ImageView;
import android.widget.ZoomControls;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.os.Bundle;
import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

public class info extends Activity {
    Bitmap bmp = BitmapFactory.decodeFile("sdcard/THQ/Para01/page1.jpg");
    ImageView img;
    Matrix matrix = new Matrix();
    Matrix savedMatrix = new Matrix();
    PointF startPoint = new PointF();
    PointF midPoint = new PointF();
    float oldDist = 1f;
    static final int NONE = 0;
    static final int DRAG = 1;
    static final int ZOOM = 2;
    int mode = NONE;

    // img.setImageBitmap(bmp);
    private int imCurrentPhotoIndex = 0;

    private int[] imPhotoIds = new int[] { R.drawable.info, R.drawable.info1,
            R.drawable.info2, R.drawable.info3, R.drawable.info4,
            R.drawable.info5, R.drawable.info6 };

    Button ibd1, ibd2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // fullscreen starts
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // fullscreen code ends
//img.setb
        setContentView(R.layout.info);
        showPhoto(imCurrentPhotoIndex);

        ibd1 = (Button) findViewById(R.id.next);
        ibd2 = (Button) findViewById(R.id.prev);



        ibd1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                imCurrentPhotoIndex++;

                if (imCurrentPhotoIndex < 7)
                    showPhoto(imCurrentPhotoIndex);
                else
                    imCurrentPhotoIndex--;

                // ///

            }
        });

        ibd2.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                imCurrentPhotoIndex--;

                if (imCurrentPhotoIndex > -1)
                    showPhoto(imCurrentPhotoIndex);
                else
                    imCurrentPhotoIndex++;

                // ///

            }
        });

    }

    protected void onSaveInstanceState(Bundle outState) {
        outState.putInt("photo_index", imCurrentPhotoIndex);
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        imCurrentPhotoIndex = savedInstanceState.getInt("photo_index");
        showPhoto(imCurrentPhotoIndex);
        super.onRestoreInstanceState(savedInstanceState);
    }

    private void showPhoto(int photoIndex) {
        ImageView imageView = (ImageView) findViewById(R.id.image_view);
        // imageView.setImageResource(imPhotoIds[photoIndex]);
        imageView.setImageResource(imPhotoIds[photoIndex]);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        // getMenuInflater().inflate(R.menu.starting_point, menu);
        return true;
    }

}

你能帮我让它读取并显示文件夹“ sdcard\THQ\something.png”中的图像吗?

4

2 回答 2

0
    Bitmap bmp = BitmapFactory.decodeFile("mnt\\sdcard\\THQ\\Info\\info.jpg");
ImageView img = (ImageView) findViewById(R.id.image_view);
        img.setImageBitmap(bmp);

这就是我们从存储卡文件夹中显示照片所需的一切;

于 2013-08-21T02:35:59.243 回答
0

首先,您使用此代码从文件夹中获取图像列表

ArrayList<String> pathList = new ArrayList<String>();// 
File[] listFile;

public void getFromSdcard()
{
    File file= new File(android.os.Environment.getExternalStorageDirectory(),"YOUR_FOLDER_NAME");

        if (file.isDirectory())
        {
            listFile = file.listFiles();


            for (int i = 0; i < listFile.length; i++)
            {

                pathList.add(listFile[i].getAbsolutePath());

            }
        }
}

然后您可以使用 BitmapFactory 显示解码并将其显示到您的图像视图

Bitmap bitmap = BitmapFactory.decodeFile(pathList.get(index));
imageview.setImageDrawable(bitmap);

希望我的回答能帮到你:)

于 2013-08-20T15:10:54.467 回答