Android布局生成图片并保存

来源:互联网 发布:朗动轮毂数据 编辑:程序博客网 时间:2024/06/05 11:49
     Bitmap bmp = Bitmap.createBitmap(rl.getWidth(), rl.getHeight(), Bitmap.Config.ARGB_8888);     rl.draw(new Canvas(bmp));     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");     String time = dateFormat.format(new Date());     String path = Environment.getExternalStorageDirectory().getPath() + "/doutu/";     File dir = new File(path);     if (!dir.exists()) {         dir.mkdirs();     }     String photoUrl = path + time + ".png";//换成自己的图片保存路径     File file = new File(photoUrl);     try {         stream = new FileOutputStream(file);         compress = bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);     } catch (FileNotFoundException e) {         e.printStackTrace();     }     if (compress) {         sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));         Toast.makeText(getApplicationContext(), "保存到:" + file, Toast.LENGTH_SHORT).show();     }

不写这句系统图库看不到保存的图片
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));**

0 0
原创粉丝点击