package com.mzeat.ui; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import com.mzeat.R; import com.mzeat.image.crop.CropImage; import com.mzeat.image.crop.view.CropImageView; import com.mzeat.util.ImageUtils; import com.mzeat.util.ShowToast; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore.Images.ImageColumns; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; public class ImageCrop extends BaseActivity implements OnClickListener{ private CropImageView mImageView; private Bitmap mBitmap; private CropImage mCrop; private String cropPath; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_cropimage); cropPath = getIntent().getStringExtra("cropPath"); mBitmap = ImageUtils.loadImgThumbnail(cropPath); ininView(); } private void ininView() { // TODO Auto-generated method stub findViewById(R.id.btn_yes).setOnClickListener(this); findViewById(R.id.btn_cancel).setOnClickListener(this); mImageView = (CropImageView) findViewById(R.id.cropview); mImageView.setImageBitmap(mBitmap); mImageView.setImageBitmapResetBase(mBitmap, true); mCrop = new CropImage(this, mImageView); mCrop.crop(mBitmap); } private final static String FILE_SAVEPATH = Environment .getExternalStorageDirectory().getAbsolutePath() + "/MZEAT/Camera/"; @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btn_yes: Bitmap bitmap = mCrop.cropAndSave(mBitmap); // 输出裁剪的临时文件 String timestamp = new SimpleDateFormat( "yyyyMMddHHmmss").format(new Date()); // 照片命名 String filename = FILE_SAVEPATH + "mzeat_croped" + timestamp + ".jpg"; //File file = new File(fileName); try { Intent data = new Intent(); data.putExtra("fileName", filename); ImageUtils.saveImageToSD( filename, bitmap,75); setResult(ImageFilter.CROP_OK, data); finish(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); ShowToast.showMessage(ImageCrop.this, "照片保存错误。"); } break; case R.id.btn_cancel: mCrop.cropCancel(); setResult(ImageFilter.CROP_CANCEL); finish(); break; default: break; } } }