本文實例講述了android將Bitmap對象保存到SD卡中的方法。分享給大家供大家參考。具體如下:
Bitmap logoBitmap = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.arcnote_logo);ByteArrayOutputStream logoStream = new ByteArrayOutputStream();boolean res = logoBitmap.compress(Bitmap.CompressFormat.PNG,100,logoStream);//將圖像讀取到logoStream中byte[] logoBuf = logoStream.toByteArray();//將圖像保存到byte[]中Bitmap temp = BitmapFactory.decodeByteArray(logoBuf,0,logoBuf.length);//將圖像從byte[]中讀取生成Bitmap 對象 tempsaveMyBitmap("tttt",temp);//將圖像保存到SD卡中public void saveMyBitmap(String bitName,Bitmap mBitmap){ File f = new File("/sdcard/" + bitName + ".png"); try { f.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block } FileOutputStream fOut = null; try { fOut = new FileOutputStream(f); } catch (Exception e) { e.printStackTrace(); } mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); try { fOut.flush(); } catch (IOException e) { e.printStackTrace(); } try { fOut.close(); } catch (IOException e) { e.printStackTrace(); }}
希望本文所述對大家的Android程序設(shè)計有所幫助。
新聞熱點
疑難解答
圖片精選