Android关于相机使用的一点思考

it2026-01-04  6

文章目录

1.相机使用2.流的转换(byte[] -> bitmap)3.一些问题3.1 返回data为null3.2 权限申请3.3 路径设置 4.参考建议

1.相机使用

需要以下变量: MediaStore.ACTION_IMAGE_CAPTURE imgURI file

具体参考:https://blog.csdn.net/hehe26/article/details/52921056?utm_source=blogxgwz38

2.流的转换(byte[] -> bitmap)

需要变量: imgURI InputStream-读出 ByteArrayOutputStream-写入

具体参考:https://www.cnblogs.com/yourancao520/archive/2012/06/25/2561367.html

3.一些问题

3.1 返回data为null

具体参考:startActivityForResult设置了Extra,设置URI会导致data返回null。不传URI则可以返回data。

3.2 权限申请

具体参考:Manifest.permission.CAMERA

3.3 路径设置

具体参考:fileProvider使用,涉及到meta-data标签 参考如下设置:

// Manifest.xml <provider android:authorities="${applicationId}.fileprovider" android:name="androidx.core.content.FileProvider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"/> </provider> //xml/file_paths.xml由于安全机制,所以需要(Android10) <paths> <cache-path name="my_imgs_cache" path="." /> </paths>

设置的时候注意可以根据路径的不同使用不同标签:

4.参考建议

1. 《第一行代码》—— 2. https://blog.csdn.net/hehe26/article/details/52921056?utm_source=blogxgwz38 3. https://blog.csdn.net/u014038534/article/details/52895686/ 4. https://www.cnblogs.com/yourancao520/archive/2012/06/25/2561367.html

前人栽树,后人乘凉。

最新回复(0)