Android界面调试的基本方法---bitmap显示出来
来源:互联网 发布:mac 建筑 软件 收费吗 编辑:程序博客网 时间:2024/06/05 04:13
Android界面调试的基本方法—bitmap显示出来
大家在代码中是不是经常会遇到bitmap呢?你们在分析、解决问题的时候有没有想过看看这个bitmap到底是什么,对不对劲?
(Drawable之类的也是可以转化成bitmap的)
下面提供一种方法就是将:bitmap转换成jpeg图片,并且在gallery中显示出来的代码。
这个例子很简单,希望对大家在分析问题的时候有帮助 =>
static int mFilePathNum = 0; public static void saveBitmapImage(Bitmap source, Context context) {//只要是Context对象都行 // We should store image data earlier than insert it to ContentProvider, // otherwise we may not be able to generate thumbnail in time. String directory = "/storage/sdcard0/Pictures";//存储路径 String filename = "123_" + mFilePathNum + ".jpg";//名字,随便你定义 mFilePathNum ++; OutputStream outputStream = null; String filePath = directory + "/" + filename; try { File dir = new File(directory); if (!dir.exists()) dir.mkdirs(); File file = new File(directory, filename); outputStream = new FileOutputStream(file); source.compress(Bitmap.CompressFormat.JPEG, 75, outputStream); } catch (FileNotFoundException ex) { Log.v(TAG, "yunhen FileNotFoundException :" + ex); return ; } catch (IOException ex) { Log.v(TAG, "yunhen IOException :" + ex); return ; } finally { if (outputStream!= null){ try { outputStream.close(); } catch (Throwable t) { // do nothing } } } // Read back the compressed file size. long size = new File(directory, filename).length(); ContentValues values = new ContentValues(9); // That filename is what will be handed to Gmail when a user shares a // photo. Gmail gets the name of the picture attachment from the // "DISPLAY_NAME" field. values.put(MediaStore.Images.ImageColumns.DATA, filePath); values.put(MediaStore.Images.ImageColumns.TITLE, filename); values.put(MediaStore.Images.Media.DISPLAY_NAME, filename); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); values.put(MediaStore.Images.Media.DATA, filePath); values.put(MediaStore.Images.Media.SIZE, size); context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); Log.e("yunhen", "yunhen SaveBitmapImage filePath = " + filePath); }
阅读全文
0 0
- Android界面调试的基本方法---bitmap显示出来
- 如何让Android编辑界面显示出来
- Android基本调试方法
- 关于今天扩展界面不显示出来的问题
- Android中让界面全屏显示的方法
- Android的Menu显示不出来
- Android Bitmap基本介绍
- Android 4K高清图片解码显示(2)BitmapFactory常用Bitmap的解码方法
- Android基本的界面组件
- Android 界面的基本属性
- Android 7.0 通话界面(InCallUI)是怎么出来的。
- Android一种欢迎界面全屏显示方法
- 查找系统电话界面,显示出来
- android 获取Bitmap 的两种方法
- android上Bitmap获取的方法
- android获得Bitmap的三种方法
- Android Bitmap类的常用方法
- android 获取Bitmap 的两种方法
- 354. Russian Doll Envelopes
- flume之intercept
- 【Cumputer】《第一次机房收费系统》总结三 组合查询
- 使用Chisel来突破公司代理服务器的封锁
- SourceTree解决冲突
- Android界面调试的基本方法---bitmap显示出来
- 事件总线框架EventBus和Otto学习笔记
- phpcmsv9 内容页调用{date('Y-m-d',time($inputtime))} 结果为1970-01-01.
- Linux目录结构
- 线程池ThreadPoolExecutor的使用以及理解
- 在github的readme添加图片
- 受限玻尔兹曼机
- python3应用openpyxl小结
- Chapter3 字符串、向量和数组