最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)從相機(jī)或相冊獲取圖片裁剪

 更新時(shí)間:2015年10月09日 13:59:12   投稿:mrr  
當(dāng)我們需要上傳圖片時(shí),想要裁剪成我們需要的尺寸大小,android手機(jī)都帶有這個(gè)功能,很容易,那么此功能是如何實(shí)現(xiàn)的呢?下面小編給大家介紹Android開發(fā)從相機(jī)或相冊獲取圖片裁剪,需要的朋友可以參考下

廢話不多說了,直接給大家貼代碼了。

package com.only.android.app;
import java.io.File;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.only.android.R;
public class CopyOfImageScaleActivity extends Activity implements View.OnClickListener {
 /** Called when the activity is first created. */
 private Button selectImageBtn;
 private ImageView imageView;
 private File sdcardTempFile;
 private AlertDialog dialog;
 private int crop = 180;
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.imagescale);
  selectImageBtn = (Button) findViewById(R.id.selectImageBtn);
  imageView = (ImageView) findViewById(R.id.imageView);
  selectImageBtn.setOnClickListener(this);
  sdcardTempFile = new File("/mnt/sdcard/", "tmp_pic_" + SystemClock.currentThreadTimeMillis() + ".jpg");
 }
 @Override
 public void onClick(View v) {
  if (v == selectImageBtn) {
   if (dialog == null) {
    dialog = new AlertDialog.Builder(this).setItems(new String[] { "相機(jī)", "相冊" }, new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which) {
      if (which == 0) {
       Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
       intent.putExtra("output", Uri.fromFile(sdcardTempFile));
       intent.putExtra("crop", "true");
       intent.putExtra("aspectX", 1);// 裁剪框比例
       intent.putExtra("aspectY", 1);
       intent.putExtra("outputX", crop);// 輸出圖片大小
       intent.putExtra("outputY", crop);
       startActivityForResult(intent, 101);
      } else {
       Intent intent = new Intent("android.intent.action.PICK");
       intent.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
       intent.putExtra("output", Uri.fromFile(sdcardTempFile));
       intent.putExtra("crop", "true");
       intent.putExtra("aspectX", 1);// 裁剪框比例
       intent.putExtra("aspectY", 1);
       intent.putExtra("outputX", crop);// 輸出圖片大小
       intent.putExtra("outputY", crop);
       startActivityForResult(intent, 100);
      }
     }
    }).create();
   }
   if (!dialog.isShowing()) {
    dialog.show();
   }
  }
 }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  if (resultCode == RESULT_OK) {
   Bitmap bmp = BitmapFactory.decodeFile(sdcardTempFile.getAbsolutePath());
   imageView.setImageBitmap(bmp);
  }
 }
}

以上代碼很簡單,相信大家都可以看的懂吧,欲了解更多信息請持續(xù)關(guān)注本站,謝謝。

相關(guān)文章

最新評論

神木县| 萨嘎县| 镇原县| 会理县| 七台河市| 嵊泗县| 阳江市| 乐都县| 谷城县| 濮阳县| 台山市| 普定县| 来凤县| 紫金县| 巴马| 信宜市| 高清| 东山县| 博野县| 湖南省| 呼图壁县| 夏邑县| 沙河市| 蒙山县| 班玛县| 武乡县| 新余市| 邵阳县| 玉门市| 仪征市| 东源县| 开阳县| 文山县| 共和县| 芒康县| 历史| 嘉鱼县| 青河县| 沧州市| 通榆县| 三亚市|