由于我是 android 新手,所以我创建了一个项目,我只想保存来自的图像视图,这GridView
意味着单击图像后它将显示,所以我想将该图像保存在 SD 卡上。
public class AndroidGridViewActivity extends Activity {
private static final String TAG = "AndroidGridViewActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView = (GridView) findViewById(R.id.grid_view);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent i = new Intent(getApplicationContext(),
Full_Image_Activity.class);
i.putExtra("id", position);
startActivity(i);
Log.v(TAG, "Clicked on photo");
}
});
}
}
public class Full_Image_Activity extends Activity {
private static final String TAG = "Full_Image_Activity";
Button save;
Bitmap bm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
Intent i = getIntent();
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
imageView.setImageResource(imageAdapter.mThumbIds[position]);
Log.v(TAG, "Image Opened...");
}
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public Integer[] mThumbIds = { R.drawable.imagesa, R.drawable.imagesb,
R.drawable.imagesc, R.drawable.imagesd, R.drawable.imagese,
R.drawable.imagesf, R.drawable.imagesg, R.drawable.imagesh,
R.drawable.imagesi, R.drawable.imagesj, R.drawable.imagesk,
R.drawable.imagesl };
public ImageAdapter(Context c) {
mContext = c;
}
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public Object getItem(int position) {
return mThumbIds[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
return imageView;
}
}