Android 儲存bitmap到相簿

2021-07-09 06:17:04 字數 1746 閱讀 6982

安卓原生的儲存相簿方法可以用但是可調引數很少,對三星這樣的手機支援不好,的建立時間一般為1970.1.1,可以通過複寫android原生的方法來新增相關引數,比如**建立時間和gps位置資訊什麼的

下面是儲存到相簿用的函式

/**

* insert an image and create a thumbnail for it.

** @param cr the content resolver to use

* @param source the stream to use for the image

* @param title the name of the image

* @param description the description of the image

* @return the url to the newly created image, ornullif the image failed to be stored

* for any reason.

*/public static string insertimage(contentresolver cr, bitmap source,

string title, string description, string filename) finally

long id = contenturis.parseid(url);

// wait until mini_kind thumbnail is generated.

bitmap minithumb = mediastore.images.thumbnails.getthumbnail(cr, id,

mediastore.images.thumbnails.mini_kind, null);

// this is for backward compatibility.

bitmap microthumb = storethumbnail(cr, minithumb, id, 50f, 50f,

mediastore.images.thumbnails.micro_kind);

} else

} catch (exception e)

}if (url != null)

return stringurl;

}private static final bitmap storethumbnail(

contentresolver cr,

bitmap source,

long id,

float width, float height,

int kind) catch (filenotfoundexception ex) catch (ioexception ex)

}

呼叫方法

try  catch (exception e) 

//對某些不更新相簿的應用程式強制重新整理

intent intent2 = new intent(intent.action_media_scanner_scan_file);

uri uri = uri.fromfile(new file("/sdcard/image.jpg"));//固定寫法

intent2.setdata(uri);

photoactivity.this.sendbroadcast(intent2);

android記憶體優化 Bitmap

眾說周知在android開發中bitmap是吃記憶體的大戶,所以談到android記憶體優化首先得對bitmap進行優化 優化方法主要有 1 對於無用的bitmap要及時進行 釋放bitmap的方法 if bitmap null bitmap.isrecycled bitmap.recycle 方法...

儲存BITMAP到檔案

gdi中位圖物件是很常見的gdi物件,但是無論是sdk,還是mfc都沒有提供現在 的函式或是方法來將乙個位圖物件儲存為乙個bmp檔案,這裡介紹一下儲存方法。位 件格式 dib檔案有四個主要部分 檔案表頭 bitmapfileheader 資訊表頭 bitmapinfoheader 調色盤 不一定有 ...

Android 優化Bitmap避免OOM

使用android提供的bitmapfactory解碼時,往往會因為過大而遇到 outofmemoryerror的異常。要想正常使用,一種簡便的方式是分配更少的記憶體空間來儲存,即在載入的時候以犧牲質量為代價,將進行放縮,這是一種避免oom所採用的解決方法。但是,這種方法是得不償失的,犧牲了質量。在...