本文实例为大家分享了android相机管理工具类的具体代码,供大家参考,具体内容如下
package com.utils.tools; import java.io.bufferedoutputstream; import java.io.file; import java.io.fileoutputstream; import com.shennongshi.dingdong.r; import com.shennongshi.dingdong.pztools.intentconstant.requestcode; import com.third.imageloader.imagecache; import android.app.activity; import android.content.intent; import android.graphics.bitmap; import android.os.environment; import android.text.textutils; public class camerautils { private static final string pictures = "picture"; private static string img_path_name = ""; public static void getimagefromalbum(activity act) { intent intent = new intent(intent.action_pick); intent.settype("image/*"); act.startactivityforresult(intent, requestcode.request_code_pick_image); } public static void getimagefromcamera(activity act) { string state = environment.getexternalstoragestate(); if (state.equals(environment.media_mounted)) { intent getimagebycamera = new intent("android.media.action.image_capture"); act.startactivityforresult(getimagebycamera, requestcode.request_code_capture_cameia); } else { xtoaster.show(r.string.qqryjcrsdk); } } public static void createfile(activity act) { if (textutils.isempty(img_path_name)) { string path = imagecache.getdiskcachedir(act, pictures).getabsolutepath(); file file = new file(path); if (!file.exists()) file.mkdirs(); img_path_name = path + "/" + system.currenttimemillis() + ".jpg"; } } public static boolean saveimage(bitmap photo) { try { bufferedoutputstream bos = new bufferedoutputstream(new fileoutputstream(img_path_name, false)); photo.compress(bitmap.compressformat.jpeg, 100, bos); bos.flush(); bos.close(); } catch (exception e) { return false; } return true; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
Xamarin 安卓 相机 各种坑 目标API Android 6以后,我选的目标API版本是 Android 10
Android 9.0+软件某些功能突然暴毙:cleartext not permitted
Android : Resource is not a Drawable (color or path)
Flutter问题集锦——Android Studio 4.0.1 在AVD Manger中启动模拟器报“unable to locate abd”
网友评论