//调用本地相机
Intent camare = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camare, 2);
break;
// 调用本地相册
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
startActivityForResult(intent, 1);
break;
case 2:// 位置
break;
case 3:// 文件
Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT);
innerIntent.setType("*/*");
Intent wrapperIntent = Intent.createChooser(innerIntent, null);
startActivityForResult(wrapperIntent, 3);
break;
case 4:
// 添加视频
Intent innerVideo = new Intent(Intent.ACTION_GET_CONTENT);
innerVideo.setType("video/*");
Intent wrapperVideo = Intent.createChooser(innerVideo, null);
startActivityForResult(wrapperVideo, 4);
/**
* 给予客户端震动提示
*/
protected void readyOperation() {
/** 计算当前录音时长 */
long computationTime = -1L;
computationTime = -1L;
Toast mRecordTipsToast = null;
playTone(ToneGenerator.TONE_PROP_BEEP, 200);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
stopTone();
}
}, 200);
/** 按键振动时长 */
// public static final int TONE_LENGTH_MS = 200;
vibrate(50L);
}
/** 开始录音 */
public MediaRecorder startVoice() {
String PATH = "/sdcard/MyVoiceForder/Record/";
// 设置录音保存路径
mFileName = PATH + UUID.randomUUID().toString() + ".amr";
String state = android.os.Environment.getExternalStorageState();
if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
}
File directory = new File(mFileName).getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
}
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mMediaRecorder.setOutputFile(mFileName);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
try {
mMediaRecorder.prepare();
} catch (IOException e) {
}
mMediaRecorder.start();
return mMediaRecorder;
}
/** 停止录音 */
public void stopVoice() {
mMediaRecorder.stop();
mMediaRecorder.release();
mMediaRecorder = null;
}
// 图的剪裁
private void startPhotoZoom(Uri uri, int size) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
// crop为true是设置在开启的intent中设置显示的view可以剪裁
intent.putExtra("crop", "true");
// aspectX aspectY 是宽高的比例
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
// outputX,outputY 是剪裁图片的宽高
intent.putExtra("outputX", size);
intent.putExtra("outputY", size);
intent.putExtra("return-data", true);
startActivityForResult(intent, BaoliaoActivity.PHOTO_REQUEST_CUT);
}
/**
* 本地图片转换为bitmap对象
*/
public Bitmap convertToBitmap(String path, int w, int h) {
BitmapFactory.Options opts = new BitmapFactory.Options();
// 设置为ture只获取图片大小
opts.inJustDecodeBounds = true;
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
// 返回为空
BitmapFactory.decodeFile(path, opts);
int width = opts.outWidth;
int height = opts.outHeight;
float scaleWidth = 0.f, scaleHeight = 0.f;
if (width > w || height > h) {
// 缩放
scaleWidth = ((float) width) / w;
scaleHeight = ((float) height) / h;
}
opts.inJustDecodeBounds = false;
float scale = Math.max(scaleWidth, scaleHeight);
opts.inSampleSize = (int) scale;
WeakReference<Bitmap> weak = new WeakReference<Bitmap>(BitmapFactory.decodeFile(path, opts));
return Bitmap.createScaledBitmap(weak.get(), w, h, true);
}
/**
* 获取视频的缩略图 先通过ThumbnailUtils来创建一个视频的缩略图
*/
private Bitmap getVideoThumbnail(String videoPath, int width, int height, int kind) {
Bitmap bitmap = null;
// 获取视频的缩略图
bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, kind);
System.out.println("w" + bitmap.getWidth());
System.out.println("h" + bitmap.getHeight());
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}