android編程實(shí)現(xiàn)系統(tǒng)圖片剪裁的方法
本文實(shí)例講述了android編程實(shí)現(xiàn)系統(tǒng)圖片剪裁的方法。分享給大家供大家參考,具體如下:
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"; } }
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android 開發(fā)隨手筆記之使用攝像頭拍照
- Android調(diào)用手機(jī)拍照功能的方法
- android 拍照和上傳的實(shí)現(xiàn)代碼
- android系統(tǒng)在靜音模式下關(guān)閉camera拍照聲音的方法
- Android拍照保存在系統(tǒng)相冊(cè)不顯示的問(wèn)題解決方法
- android圖像繪制(六)獲取本地圖片或拍照?qǐng)D片等圖片資源
- Android實(shí)現(xiàn)讀取相機(jī)(相冊(cè))圖片并進(jìn)行剪裁
- android照相、相冊(cè)獲取圖片剪裁報(bào)錯(cuò)的解決方法
- Android編程實(shí)現(xiàn)圖片拍照剪裁的方法
相關(guān)文章
Android程序開發(fā)之手機(jī)APP創(chuàng)建桌面快捷方式
這篇文章主要介紹了Android程序開發(fā)之手機(jī)APP創(chuàng)建桌面快捷方式 的相關(guān)資料,需要的朋友可以參考下2016-04-04android studio錯(cuò)誤: 常量字符串過(guò)長(zhǎng)的解決方式
這篇文章主要介紹了android studio錯(cuò)誤: 常量字符串過(guò)長(zhǎng)的解決方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04Android BLE 藍(lán)牙開發(fā)之實(shí)現(xiàn)掃碼槍基于BLESSED開發(fā)
這篇文章主要介紹了Android BLE 藍(lán)牙開發(fā)之實(shí)現(xiàn)掃碼槍基于BLESSED開發(fā),示例代碼介紹了第三方庫(kù)BLESSED for Android的使用,需要的朋友可以參考下2022-03-03Android網(wǎng)絡(luò)編程之UDP通信模型實(shí)例
這篇文章主要介紹了Android網(wǎng)絡(luò)編程之UDP通信模型實(shí)例,本文給出了服務(wù)端代碼和客戶端代碼,需要的朋友可以參考下2014-10-10Android 中在有序廣播中添加自定義權(quán)限的實(shí)例
這篇文章主要介紹了Android 中在有序廣播中添加自定義權(quán)限的實(shí)例的相關(guān)資料,這里對(duì)有序廣播的用法進(jìn)行了詳細(xì)介紹并附有簡(jiǎn)單實(shí)例,需要的朋友可以參考下2017-07-07Android存儲(chǔ)訪問(wèn)框架的使用小結(jié)
這篇文章主要介紹了Android存儲(chǔ)訪問(wèn)框架的使用,存儲(chǔ)訪問(wèn)框架API和MediaStore?API的差異,在于存儲(chǔ)訪問(wèn)框架API,是基于系統(tǒng)文件選擇框的,用戶選擇了文件,那么相當(dāng)于授權(quán)了,?可以訪問(wèn)所有類型的文件,需要的朋友可以參考下2022-01-01Android實(shí)現(xiàn)實(shí)時(shí)搜索框功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)實(shí)時(shí)搜索框功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09