此代码从 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
”中的图像吗?