资源说明:android 图片 拍照 删除 添加 旋转
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.image_show);
path = Environment.getExternalStorageDirectory();
file = new File(path + "/MapGIS/myImg/");
file.mkdirs();
getSD();
mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
gallery = (Gallery) findViewById(R.id.gallery);
mSwitcher.setFactory(this);
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
mSwitcher.setImageURI(imgList1.get(position).getUri());
pos = position;
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
// 拍照按钮
Button paizhao = (Button) this.findViewById(R.id.paizhao);
paizhao.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// 判断SD卡是不是能用
if (isAvaiableSpace(600)) {
// 当前可用
Intent imgIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = new Date();
nameTmp = dateFormat.format(date);
imgIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(file, nameTmp + ".jpg")));
startActivityForResult(imgIntent, 1);
} else
// 当前不可用
{
Toast.makeText(PhotoShowActivity.this, "SD卡不可用!", Toast.LENGTH_SHORT).show();
}
}
});
// 删除按钮
Button shanchu = (Button) this.findViewById(R.id.shanchu);
shanchu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (!imgList1.isEmpty()) {
// 存放图片名字
final String fname = imgList1.get(pos).getName();
new AlertDialog.Builder(PhotoShowActivity.this).setIcon(R.drawable.alert_dialog_icon)
.setTitle("警告").setMessage("确认删除此图片?")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
File SDPATH2 = Environment.getExternalStorageDirectory();
File file2 = new File(SDPATH2 + "/MapGIS/myImg/" + fname);
file2.delete();
imgList1.remove(pos);
gallery.setAdapter(new ImageAdapter(PhotoShowActivity.this));
mSwitcher.reset();
Toast.makeText(PhotoShowActivity.this, "图片已成功删除!", Toast.LENGTH_SHORT).show();
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(PhotoShowActivity.this, "你取消了删除图片!", Toast.LENGTH_SHORT).show();
}
}).show();
} else {
Toast.makeText(PhotoShowActivity.this, "当前没有图片可以删除", Toast.LENGTH_SHORT).show();
}
}
});
// 向左旋转图片按钮
xuanzhuan2 = (Button) this.findViewById(R.id.xuanzhuan2);
xuanzhuan2.setOnClickListener(new MyXuanZhuanClick(270));
// 向右旋转图片按钮
xuanzhuan = (Button) this.findViewById(R.id.xuanzhuan);
xuanzhuan.setOnClickListener(new MyXuanZhuanClick(90));
}
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。
English
