av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:4日期: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
相關文章:
主站蜘蛛池模板: 亚洲免费视频网址 | 精品国产乱码久久久久久果冻传媒 | 999精品网 | 97久久精品午夜一区二区 | 91影视| 激情一区 | 日韩免费网站 | 久久精品视频亚洲 | 中文天堂在线观看 | 精品久久久久久国产 | 国产一级特黄真人毛片 | 在线观看av不卡 | 91极品视频 | 欧美日韩国产一区二区 | 区一区二区三在线观看 | 欧美日韩亚洲一区 | 天天拍夜夜爽 | 日韩欧美一区二区三区在线播放 | 草久网| 国产精品久久在线 | 国产精品亚洲二区 | 国产视频久久久 | 国产精品成人一区 | 国产婷婷色综合av蜜臀av | 欧美日韩中文字幕在线 | 在线视频一区二区三区 | 久久国产精品精品国产色婷婷 | 91精品91久久久 | 国产一级片免费视频 | 欧美久久视频 | 91新视频 | 欧美中文在线 | 日本高清视频网站 | 免费的色网站 | 免费黄色a视频 | 成人欧美一区二区三区黑人孕妇 | 在线免费观看黄色网址 | 狠狠操网站| 久久男人天堂 | 久久美女网| 欧美日韩成人在线观看 |