91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

拍照剪切and獲取sd卡中的圖片

發布時間:2020-07-25 00:47:59 來源:網絡 閱讀:367 作者:android紫函 欄目:移動開發

package com.truekey.alarmclock.user;

import java.io.File;

import android.app.Activity;

import android.app.Dialog;

import android.content.Context;

import android.content.Intent;

import android.content.SharedPreferences;

import android.graphics.Bitmap;

import android.graphics.drawable.BitmapDrawable;

import android.graphics.drawable.Drawable;

import android.net.Uri;

import android.os.Bundle;

import android.os.Environment;

import android.provider.MediaStore;

import android.view.Gravity;

import android.view.LayoutInflater;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.Window;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.RelativeLayout.LayoutParams;

import android.widget.TextView;

import com.truekey.alarmclock.R;


public class UserInfoActivity extends Activity {

ImageView user_header_p_w_picpath;

Dialog pictureDialog;

View pictureView;

Button takePictureBtn, allPicture, cancle;

private static final int SCALE = 15;// 照片縮小比例

String imgBase64;

String fileName = null;

ImageView iv_title_left, iv_title_right;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.user_info_layout);

iv_title_right = (ImageView) findViewById(R.id.iv_title_right);

iv_title_left = (ImageView) findViewById(R.id.iv_title_left);

user_header_p_w_picpath = (ImageView) findViewById(R.id.user_header_p_w_picpath);

TextView nicheng_tv = (TextView) findViewById(R.id.nicheng_tv);

pictureDialog();

}


public void onClick(View v) {

switch (v.getId()) {

case R.id.user_header_p_w_picpath:

pictureDialog.show();

pictureDialog.getWindow().setLayout(LayoutParams.MATCH_PARENT,

LayoutParams.WRAP_CONTENT);

break;

case R.id.iv_title_right:

finish();

overridePendingTransition(R.anim.home_main_last_twoactivity_out,

R.anim.ptr_slide_out_to_bottom);

break;

case R.id.iv_title_left:

finish();

overridePendingTransition(R.anim.home_main_last_twoactivity_in,

R.anim.ptr_slide_out_to_bottom);

default:

break;

}

}

// 拍照布局

public void pictureDialog() {

pictureView = LayoutInflater.from(UserInfoActivity.this).inflate(

R.layout.takepicture_dialog, null);

cancle = (Button) pictureView.findViewById(R.id.cancle);

takePictureBtn = (Button) pictureView.findViewById(R.id.take_picture);

takePictureBtn.setOnClickListener(new ButtonOnClickListener());

// 所有的圖片選取。。

allPicture = (Button) pictureView.findViewById(R.id.all_picture);

// 所有圖片

allPicture.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION_PICK, null);

intent.setDataAndType(

MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "p_w_picpath/*");

startActivityForResult(intent, 1);

}

});


// 取消

cancle.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

pictureDialog.dismiss();

}

});

if (pictureView != null) {

/* 自定義對話框 */

pictureDialog = new Dialog(this, R.style.mydialog);

pictureDialog.setContentView(pictureView);

pictureDialog.setCancelable(false);

Window window = pictureDialog.getWindow();

window.setWindowAnimations(R.style.AlterDialogAnima);

window.setGravity(Gravity.BOTTOM);

}

}

public final static int CAMERA_RESULT = 8888;

// 拍照獲取圖片

private class ButtonOnClickListener implements View.OnClickListener {

@Override

public void onClick(View v) {

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

// 下面這句指定調用相機拍照后的照片存儲的路徑

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(

Environment.getExternalStorageDirectory(), "xiaoma.jpg")));

startActivityForResult(intent, 2);

}

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if (resultCode == RESULT_OK) {

switch (requestCode) {

case 1:

startPhotoZoom(data.getData());

break;

// 如果是調用相機拍照時

case 2:

File temp = new File(Environment.getExternalStorageDirectory()

+ "/xiaoma.jpg");

startPhotoZoom(Uri.fromFile(temp));

break;

// 取得裁剪后的圖片

case 3:

/**

* 非空判斷大家一定要驗證,如果不驗證的話, 在剪裁之后如果發現不滿意,要重新裁剪,丟棄

* 當前功能時,會報NullException,小馬只 在這個地方加下,大家可以根據不同情況在合適的 地方做判斷處理類似情況

*

*/

if (data != null) {

setPicToView(data);

}

break;

default:

break;

}

}

}

/**

* 裁剪圖片方法實現

*

* @param uri

*/

public void startPhotoZoom(Uri uri) {

Intent intent = new Intent("com.android.camera.action.CROP");

intent.setDataAndType(uri, "p_w_picpath/*");

// 下面這個crop=true是設置在開啟的Intent中設置顯示的VIEW可裁剪

intent.putExtra("crop", "true");

// aspectX aspectY 是寬高的比例

intent.putExtra("aspectX", 1);

intent.putExtra("aspectY", 1);

// outputX outputY 是裁剪圖片寬高

intent.putExtra("outputX", 150);

intent.putExtra("outputY", 150);

intent.putExtra("return-data", true);

startActivityForResult(intent, 3);

}

/**

* 保存裁剪之后的圖片數據

*

* @param picdata

*/

private void setPicToView(Intent picdata) {

Bundle extras = picdata.getExtras();

if (extras != null) {

Bitmap photo = extras.getParcelable("data");

Drawable drawable = new BitmapDrawable(photo);

pictureDialog.dismiss();

// 為防止原始圖片過大導致內存溢出,這里先縮小原圖顯示,然后釋放原始Bitmap占用的內存

Bitmap choosepicture = ImageTools.toRoundBitmap2(photo);

// 釋放原始圖片占用的內存,防止out of memory異常發生

photo.recycle();

user_header_p_w_picpath.setImageBitmap(choosepicture);

}

}


// 用于保存圖片

public void putSharedpreference(String takepicture) {

SharedPreferences shared = getSharedPreferences("temp",

Context.MODE_PRIVATE);

SharedPreferences.Editor edit = shared.edit();

edit.putString("picture", takepicture);

edit.commit();

}


public String getSharedpreference() {

SharedPreferences shared = getSharedPreferences("temp",

Context.MODE_PRIVATE);

return shared.getString("picture", "");

}


@Override

protected void onDestroy() {

super.onDestroy();

putSharedpreference(fileName);

}


@Override

protected void onResume() {

super.onResume();


}

}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

鹤岗市| 四子王旗| 福建省| 深圳市| 江油市| 曲水县| 巧家县| 盐山县| 富宁县| 屏南县| 高台县| 当阳市| 新晃| 信阳市| 柯坪县| 清流县| 高陵县| 铜山县| 仙游县| 南丰县| 嘉鱼县| 衡阳县| 两当县| 隆化县| 巴林右旗| 明水县| 铜陵市| 连江县| 彰武县| 温宿县| 禹州市| 龙门县| 安庆市| 古蔺县| 晋江市| 色达县| 丰顺县| 太保市| 忻城县| 通辽市| 汉寿县|