国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Android 獲取drawable目錄圖片 并存入指定文件的步驟詳解

瀏覽:2日期:2022-09-25 09:17:44

第一步:獲取存儲的路徑 我們用/sdcard/Android/data/包名/的路徑 方便我們測試查看

String path=MyApplication.getContextObject().getExternalFilesDir('').toString(); File file=new File(path);

第二步:根據該文件中存儲的路徑信息在文件系統上創建一個新的空文件

File finalImageFile = new File(file, System.currentTimeMillis() + '.jpg'); try { finalImageFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); }

第三步:將字節放入文件輸出流

FileOutputStream fos = null; try { fos = new FileOutputStream(finalImageFile); } catch (FileNotFoundException e) { e.printStackTrace(); }

第四步:將圖片壓縮成圖片格式

BitmapDrawable bitmapDrawable = (BitmapDrawable)MyApplication.getContextObject().getResources().getDrawable(R.drawable.account); Bitmap bitmap=bitmapDrawable.getBitmap(); if (bitmap == null) { Toast.makeText(MyApplication.getContextObject(), '圖片不存在',Toast.LENGTH_LONG).show(); return; } bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); try { fos.flush(); fos.close(); Toast.makeText(MyApplication.getContextObject(), '圖片保存在:'+ finalImageFile.getAbsolutePath(), Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); }

完整代碼

String path=MyApplication.getContextObject().getExternalFilesDir('').toString(); File file=new File(path); File finalImageFile = new File(file, System.currentTimeMillis() + '.jpg'); try { finalImageFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } FileOutputStream fos = null; try { fos = new FileOutputStream(finalImageFile); } catch (FileNotFoundException e) { e.printStackTrace(); } BitmapDrawable bitmapDrawable = (BitmapDrawable)MyApplication.getContextObject().getResources().getDrawable(R.drawable.account); Bitmap bitmap=bitmapDrawable.getBitmap(); if (bitmap == null) { Toast.makeText(MyApplication.getContextObject(), '圖片不存在',Toast.LENGTH_LONG).show(); return; } bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); try { fos.flush(); fos.close(); Toast.makeText(MyApplication.getContextObject(), '圖片保存在:'+ finalImageFile.getAbsolutePath(), Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); }

總結

到此這篇關于Android 獲取drawable目錄圖片 并存入指定文件的文章就介紹到這了,更多相關android 目錄圖片存入指定文件內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Android
相關文章:
主站蜘蛛池模板: 日本乱子伦xxxx | 免费观看一级欧美大 | 欧美一级毛片俄罗斯 | 手机免费看毛片 | 国产成人免费全部网站 | 久久精品男人的天堂 | 免费成人高清视频 | a级黄色毛片免费播放视频 a级精品九九九大片免费看 | 理论片免费午夜 | 全部免费a级毛片 | 寡妇一级a毛片免费播放 | 一级片在线免费看 | 久久爱99re| 综合亚洲欧美日韩一区二区 | 波多野在线播放 | 亚洲三级在线免费观看 | 国产成人综合怡春院精品 | 欧洲亚洲综合一区二区三区 | 大陆60老妇xxxxhd | 欧美成人中文字幕 | 亚洲高清在线看 | 亚洲欧美日韩精品久久亚洲区色播 | 国产精品久久久久久一级毛片 | 一区二区三区亚洲视频 | 久久精品免观看国产成人 | 欧美三级在线看 | 国内黄色精品 | 中文日韩字幕 | 美女张开腿让男生桶出水 | 国产一级爱做片免费观看 | 老太婆性杂交毛片 | 国产在线啪 | 天天爽夜夜操 | 成人黄色免费观看 | 免费一级片视频 | 三级黄毛片 | 国产在线观看xxxx免费 | 成人18免费 | 国产乱淫视频 | 怡红院成人永久免费看 | 日韩欧美一中字暮 |