所以我有这个班级“MakePhoto”。它可以制作和保存照片。现在我想将图片保存在一个数组中。因此,当你制作一张图片时,它应该将它存储在数组[0]中,第二张图片应该存储在数组[1]等中。所以数组[0]应该引用第一张图片。这有可能吗?
PhotoMaker.java类:
package com.example.photoviewer;
import java.io.FileNotFoundException;
import com.example.keyfinder.R;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.net.Uri;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class FotoMaker extends Activity
{
ImageView iv;
Uri uriOfPicture;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.add_pic);
iv = (ImageView) findViewById(R.id.imageView);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick (View v){
takeImageFromCamera();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == 0)
{
Bitmap image=createBitmapFromURI(uriOfPicture);
iv.setImageBitmap(image);
}
Intent intent = new Intent(this,ShowPhoto.class);
intent.putExtra("uri", uriOfPicture.toString());
startActivity(intent);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (uriOfPicture != null) {
outState.putString("cameraImageUri", uriOfPicture.toString());
}
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState.containsKey("cameraImageUri")) {
uriOfPicture = Uri.parse(savedInstanceState.getString("cameraImageUri"));
}
}
/*********************************** method to take URI of the picture *******************/
public void takeImageFromCamera(){
String fileName = "new-photo-name.jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,
"Image captured by camera");
uriOfPicture = getContentResolver()
.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
Log.i("uri",uriOfPicture.toString());
Intent intent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uriOfPicture);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent,
0);
}
public Bitmap createBitmapFromURI(Uri uriOfPicture) {
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream(getApplicationContext()
.getContentResolver().openInputStream(uriOfPicture));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (bitmap != null)
return Bitmap.createScaledBitmap(bitmap, 100, 100, true);
else {
return null;
}
}
}
答案 0 :(得分:1)
只需创建一个类似
的位图数组Bitmap []arr = new Bitmap[size];
如果你不知道大小
,你可以使用像arraylist这样的容器类ArrayList<Bitmap> list = new ArrayList<Bitmap>();
list.add(reference_to_the_bitmap);