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

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

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

瀏覽:7日期: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
相關文章:
主站蜘蛛池模板: 久久久久久综合对白国产 | 国产成人免费在线 | 男女午夜 | 日韩黄色片在线观看 | 免费播放国产性色生活片 | 色碰碰 | 妖精www成人动漫在线观看 | 国产特级全黄一级毛片不卡 | 精品在线网站 | 国产a级三级三级三级 | 成年人视频在线免费看 | 免费看欧美一级特黄a毛片 免费看片aⅴ免费大片 | 国产成人综合高清在线观看 | 美国毛片亚洲社区在线观看 | 一级毛片在线免费播放 | 久久国产一片免费观看 | 中文字幕一区在线 | 午夜刺激爽爽视频免费观看 | 欧美zoofilia杂交videos | 久草视频播放 | 久久国内精品自在自线观看 | 亚洲综合干 | 好吊色综合网天天高清 | 久久99精品久久久久久三级 | 美国毛片免费一级 | 中文国产成人精品久久久 | 亚洲欧美在线不卡 | 欧美午夜精品久久久久免费视 | 99精品视频在线免费观看 | 精品中文字幕久久久久久 | 99爱在线视频这里只有精品 | 高清一级毛片 | 国产精品黄在线观看观看 | 日本xxxxx黄区免费看动漫 | 亚洲手机视频 | 国产亚洲高清视频 | 久久久久久久久久综合情日本 | 在线中文字幕精品第5页 | 亚洲另类自拍 | 亚洲欧美中文日韩在线v日本 | 国产一久久香蕉国产线看观看 |