安卓几种常用函数
1.保存图片文件到SD卡
private InputStream Bitmap2IS(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); InputStream sbs = new ByteArrayInputStream(baos.toByteArray()); return sbs; } public void onClick_SaveImageToSDCard(View view) { try { FileOutputStream fos = new FileOutputStream(ALBUM_PATH + "/QRcode.png"); // InputStream is = getResources().getAssets().open("image.jpg"); InputStream is = Bitmap2IS(bit); byte[] buf = new byte[4096]; int count = 0; while ((count = is.read(buf)) >= 0) { fos.write(buf, 0, count); } fos.close(); is.close(); /* * byte[] buffer = new byte[8192]; int count = 0; while((count = * is.read(buffer)) >= 0){ fos.write(buffer,0,count); } fos.close(); * is.close(); */ Toast.makeText(this, "写入成功!", Toast.LENGTH_LONG).show(); } catch (Exception e) { // TODO: handle exception Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。