色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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
相關文章:
主站蜘蛛池模板: 亚洲美女综合 | 在线综合+亚洲+欧美中文字幕 | 大学生久久香蕉国产线观看 | 久久观看 | 欧美精品aaa久久久影院 | 女在床上被男的插爽叫视频 | 国产高清在线看免费视频观 | 亚洲欧美中文日韩二区一区 | 成人爱爱网站在线观看 | 久草综合视频 | 久久久亚洲欧洲日产国码二区 | 天天躁天天碰天天看 | 欧美大屁股精品毛片视频 | 亚洲一区二区三区四区五区六区 | 偷拍自拍第一页 | 一级欧美过瘾大片 | 国产一区精品在线观看 | 亚洲免费中文 | 国产成人亚洲精品77 | 欧美日韩精品免费一区二区三区 | 日韩三级欧美 | 国产成人精品一区二三区2022 | 中文字幕人成不卡一区 | 三级黄色高清视频 | 国产一级特黄aaa大片 | 成人一级片在线观看 | 国产一区二区三区久久小说 | 成人免费国产欧美日韩你懂的 | 国产成人免费视频精品一区二区 | 欧美一级成人毛片视频 | 国产一级一片免费播放 | 99久久香蕉| 一级欧美一级日韩毛片99 | 一个人免费观看日本www视频 | 久久久久久久久久久观看 | 日韩精品在线免费观看 | 日本欧美一区二区三区在线 | 国产真实生活伦对白 | 在线视频亚洲一区 | 国产亚洲精品久久久久久久网站 | 国产v片在线播放免费观 |