午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

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

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

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

第二步:根據(jù)該文件中存儲的路徑信息在文件系統(tǒng)上創(chuàng)建一個新的空文件

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

第三步:將字節(jié)放入文件輸出流

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 目錄圖片存入指定文件內容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Android
相關文章:
主站蜘蛛池模板: 日本黄色片免费看 | 久久成人在线 | 日本一区二区三区视频在线观看 | 视频大全在线观看网址 | aaaaaaa毛片| 欧美男人天堂 | 中国黄色网页 | 超碰伊人 | caoporn人人| 日韩一区二区中文字幕 | 欧美乱日 | 岛国av免费观看 | 欧美成人精品一区二区三区 | 成人观看视频 | 日本道中文字幕 | a天堂中文字幕 | 日韩中文字幕视频 | 天堂在线观看中文字幕 | 日韩午夜影院 | 国产视频分类 | 最新天堂av | 日韩一区二区视频 | 日韩精品片 | 天堂中文资源在线 | 亚洲专区在线播放 | 天天看天天射 | 亚洲视频欧洲视频 | 黑人巨大精品欧美一区二区 | 超碰97久久 | 超碰在线公开免费 | 日韩精品国产精品 | 啪啪伊人 | 欧美激情综合色综合啪啪五月 | 天天在线免费视频 | 午夜在线一区 | 国产自产自拍 | 福利一二区 | 精品国产乱码久久久久久婷婷 | 17c国产精品一区二区 | 亚洲专区在线播放 | a国产视频|