真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

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

package com.truekey.alarmclock.user;

成都網(wǎng)絡(luò)公司-成都網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站10多年經(jīng)驗(yàn)成就非凡,專業(yè)從事成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè),成都網(wǎng)頁設(shè)計(jì),成都網(wǎng)頁制作,軟文發(fā)布平臺(tái),1元廣告等。10多年來已成功提供全面的成都網(wǎng)站建設(shè)方案,打造行業(yè)特色的成都網(wǎng)站建設(shè)案例,建站熱線:028-86922220,我們期待您的來電!

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) {

/* 自定義對(duì)話框 */

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);

// 下面這句指定調(diào)用相機(jī)拍照后的照片存儲(chǔ)的路徑

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;

// 如果是調(diào)用相機(jī)拍照時(shí)

case 2:

File temp = new File(Environment.getExternalStorageDirectory()

+ "/xiaoma.jpg");

startPhotoZoom(Uri.fromFile(temp));

break;

// 取得裁剪后的圖片

case 3:

/**

* 非空判斷大家一定要驗(yàn)證,如果不驗(yàn)證的話, 在剪裁之后如果發(fā)現(xiàn)不滿意,要重新裁剪,丟棄

* 當(dāng)前功能時(shí),會(huì)報(bào)NullException,小馬只 在這個(gè)地方加下,大家可以根據(jù)不同情況在合適的 地方做判斷處理類似情況

*

*/

if (data != null) {

setPicToView(data);

}

break;

default:

break;

}

}

}

/**

* 裁剪圖片方法實(shí)現(xiàn)

*

* @param uri

*/

public void startPhotoZoom(Uri uri) {

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

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

// 下面這個(gè)crop=true是設(shè)置在開啟的Intent中設(shè)置顯示的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);

}

/**

* 保存裁剪之后的圖片數(shù)據(jù)

*

* @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();

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

Bitmap choosepicture = ImageTools.toRoundBitmap2(photo);

// 釋放原始圖片占用的內(nèi)存,防止out of memory異常發(fā)生

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();

}

}


網(wǎng)站題目:拍照剪切and獲取sd卡中的圖片
文章URL:http://weahome.cn/article/ppicoi.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部