截取屏幕,并保存图片到本地(画廊)
生活随笔
收集整理的這篇文章主要介紹了
截取屏幕,并保存图片到本地(画廊)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
生成bitmap
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);//利用bitmap生成畫布Canvas canvas = new Canvas(bitmap);//把view中的內(nèi)容繪制在畫布上view.draw(canvas);保存bitmap
public static File saveImageToGallery(Context context, Bitmap bmp, String path) {// 首先保存圖片String storePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "金融礦工";File appDir = new File(storePath);if (!appDir.exists()) {appDir.mkdir();}String fileName = KGEnvironment.uid() + path + ".jpg";File file = new File(appDir, fileName);if (file.exists()) {file.delete();}try {FileOutputStream fos = new FileOutputStream(file);//通過io流的方式來壓縮保存圖片bmp.compress(Bitmap.CompressFormat.JPEG, 60, fos);fos.flush();fos.close();//保存圖片后發(fā)送廣播通知更新數(shù)據(jù)庫Uri uri = Uri.fromFile(file);context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));} catch (IOException e) {e.printStackTrace();}return file;}完成的方法調(diào)用
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);//利用bitmap生成畫布Canvas canvas = new Canvas(bitmap);//把view中的內(nèi)容繪制在畫布上view.draw(canvas); //根據(jù)需要設(shè)置路徑 saveImageToGallery(mContext, bitmap ,"bitmap");?
轉(zhuǎn)載于:https://my.oschina.net/carbenson/blog/1801523
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的截取屏幕,并保存图片到本地(画廊)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深度学习中的对抗攻击和对抗防御
- 下一篇: JAVA使用POI如何导出百万级别数据