標籤:
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 exceptionToast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();}}
安卓幾種常用函數