Create a bitmap in android to avoid Memory insufficiency. androidbitmap
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.miz.heapsize" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="11" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:largeHeap="true" > <activity android:label="@string/app_name" android:name=".MainActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
You only need to add <pre name = "code" class = "html"> android: largeHeap = "true"
Can generate 48 m oh yeah
http://www.google.com/url?q=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F8675037%2Fdoes-androids-large-heap-option-work-for-older-phones-upgraded-to-ics&sa=D&sntz=1&usg=AFQjCNE43aD9kOt0M5OUzNWaNGXP5pSM8w
Solve the problem. The android memory overflows and the Code uses threads and bitmap.
Hope to help you.
Android caches images through soft references to prevent memory overflow
Public class BitmapCache {
Static private BitmapCache cache;
/** Storage of Chche content */
Private Hashtable <Integer, MySoftRef> hashRefs;
/** Spam Reference Queue (if the referenced object has been recycled, the Reference will be saved to the queue )*/
Private ReferenceQueue <Bitmap> q;
/**
* Inherits SoftReference, so that each instance has a recognizable identifier.
*/
Private class MySoftRef extends SoftReference <Bitmap> {
Private Integer _ key = 0;
Public MySoftRef (Bitmap bmp, ReferenceQueue <Bitmap> q, int key ){
Super (bmp, q );
_ Key = key;
}
}
Private BitmapCache (){
HashRefs = new Hashtable <Integer, MySoftRef> ();
Q = new ReferenceQueue <Bitmap> ();
}
/**
* Obtain the cache instance
*/
Public static BitmapCache getInstance (){
If (cache = null ){
Cache = new BitmapCache ();
}
Return cache;
}
/**
* Reference an instance of a Bitmap object in soft reference mode and save the reference.
*/
Private void addCacheBitmap (Bitmap bmp, Integer key ){
CleanCache (); // clear spam reference
MySoftRef ref = new MySoftRef (bmp, q, key );
HashRefs. put (key, ref );
}
/**
* Obtain the instance of the corresponding Bitmap object based on the image resource ID under the specified drawable (you can obtain it from the network or local path as needed ).
*/
Public Bitmap getBitmap (int resId, Context context ){
Bitmap bmp = null;
// Check whether soft references of the Bitmap instance exist in the cache. If so, obtain them from soft references.
If (hashRefs. containsKey (resId )){
MyS... the remaining full text>
How to read Bitmap in Android note and optimize memory overflow
I found a lot of information. The following methods are summarized for reading Bitmap. 1. assume that test.png image FileInputStream is set to new FileInputStream ("/sdcard/test.png") and Bitmap bitmap = BitmapFactory under sdcard as a file stream. decodeStream (FS); 2. assume that there is a test.jpg file Bitmap = BitmapFactory IN res/drawable. decodeResource (this. getContext (). getResources (), R. drawable. test); 3. in ResourceStream mode, but not to the R file. Bitmap. bitmap = BitmapFactory. decodeStream (getClass (). getResourceAsStream ("/res/drawable/test.png"); BitmapFactory. options options = new BitmapFactory. options (); options. inSampleSize = 2; // The image width and height are 1/2 of the original size, that is, the image is the original four-point one. // the above Code can optimize memory overflow, but it only changes the image size, it cannot completely resolve the memory overflow.