編輯:關於Android編程
本文實例講述了android編程實現系統圖片剪裁的方法。分享給大家供大家參考,具體如下:
package cn.test; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import android.app.Activity; import android.content.ContentResolver; import android.content.ContentUris; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; public class CutActivity extends Activity { private Button button; private ImageView imageView; private File mCurrentPhotoFile; private Bitmap cameraBitmap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button) findViewById(R.id.button); imageView = (ImageView) findViewById(R.id.imageView); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent( "android.media.action.IMAGE_CAPTURE"); mCurrentPhotoFile = new File( "mnt/sdcard/DCIM/Camera/", getPhotoFileName()); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mCurrentPhotoFile)); startActivityForResult( intent, Activity.DEFAULT_KEYS_DIALER); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case 1: Uri imgUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; ContentResolver cr = CutActivity.this .getContentResolver(); Uri fileUri = Uri.fromFile(mCurrentPhotoFile); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri)); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Cursor cursor = cr .query(imgUri, null, MediaStore.Images.Media.DISPLAY_NAME + "='" + mCurrentPhotoFile.getName() + "'", null, null); Uri uri = null; if (cursor != null && cursor.getCount() > 0) { cursor.moveToLast(); long id = cursor.getLong(0); uri = ContentUris.withAppendedId(imgUri, id); } final Intent intent = new Intent( "com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", "true"); intent.putExtra("outputX", 380); intent.putExtra("outputY", 500); intent.putExtra("return-data", true); CutActivity.this.startActivityForResult(intent, 3); break; case 2: break; case 3: if (data != null) { cameraBitmap = (Bitmap) data.getExtras().get("data"); imageView.setImageBitmap(cameraBitmap); } break; default: break; } super.onActivityResult(requestCode, resultCode, data); } private String getPhotoFileName() { Date date = new Date(System.currentTimeMillis()); SimpleDateFormat dateFormat = new SimpleDateFormat( "'IMG'_yyyyMMdd_HHmmss"); return dateFormat.format(date) + ".jpg"; } }
希望本文所述對大家Android程序設計有所幫助。
菜單策劃:原理:使用控件繼承HorizontalScrollView,因為HorizontalScrollView提供了水平側滑的效果,然後測量菜單和內容界面的各個屬性,
在做商城的項目中,有這麼個需求,就是一個產品下有兩個價格,一個是市場價,一個是銷售價,這時要把市場價添加個刪除線;剛開始遇到這個時,在網上找了半天的資料,看到最多的就是用
Android特效專輯(十二)——仿支付寶咻一咻功能實現波紋擴散特效,精細小巧的View 先來看看這個效果 這是我的在Only上添加的效果,說實話
ES文件浏覽器連接電腦顯示登錄失敗。之前在連著電腦看著電視,不知道手機怎麼了,現在連接不上,還顯示登錄失敗。現在不知道怎麼辦。小編來給大家演示一下,當ES浏