Android相机管理工具类
程序员文章站
2023-12-19 13:40:58
本文实例为大家分享了android相机管理工具类的具体代码,供大家参考,具体内容如下
package com.utils.tools;
import j...
本文实例为大家分享了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; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。