The most common issue that you may face while working with bitmap is OutOfMemoryError. This issue occur because the garbage collector (GC) does not free the object associated with the bitmap and clear preference to pixel data fast enough, thus cause the memory allocated for the bitmap to grow until exceeding Virtual Memory limit.
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
In
order to avoid this issue, you need to do recycle() for every bitmap
as soon as it no long need. Notice that recycle () is used to free
the native object associated with this bitmap, and clear the
reference to the pixel data. This will not free the pixel data
synchronously; it simply allows it to be garbage collected if there
are no other references. The bitmap is marked as “dead”, meaning
it will throw an exception if getPixels() or setPixels() is called,
and will draw nothing. This operation cannot be reversed, so it
should only be called if you are sure there are no further uses for
the bitmap. This is an advanced call, and normally need not be
called, since the normal GC process will free up this memory when
there are no more references to this bitmap. See the code below:
public class bitmaptest extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// decode a jpg into bitmap
Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/myimage.jpg");
...
// indicate that the bitmap is no longer need and GC should
// free it asap
bitmap.recycle();
}
}
Bimap
is a little tricky, miss-use it may causes an exception. Generally
using bitmap is recommended only if you need to get detail data of
the image such as image
width,
height, and pixel data. Otherwise, bitmap should not be used in order
to avoid OutOfMemoryError. For an example, if you just want to
dispaly an image such as icon, you could you ImageView class instead
and it also provides various display options such as scaling
and
tinting. The following code below shows how to build an
ImageView
that
uses an image from drawable resources and add it to the layout.public class bitmaptest extends Activity {
private LinearLayout mLinearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
// Instantiate an ImageView and define its properties
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.my_image);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setLayoutParams(new GridView.LayoutParams(200, 200));
// Add the ImageView to the layout and set the layout as
// the content view
mLinearLayout.addView(imageView);
setContentView(mLinearLayout);
}
}
Rose Bowl 2018
ReplyDeleteRose Bowl
Sugar Bowl 2018
Sugar Bowl
Rose Bowl 2018
Rose Bowl
Orange Bowl 2018
Orange Bowl
UFC 219
Sugar Bowl
Alabama vs Clemson
Clemson vs Alabama
ReplyDeleteNational Championship
National Championship Live
National Championship 2018
National Championship 2018 Live
National Championship Game
CFP Championship
CFP National Championship
National Championship
National Championship Live
National Championship 2018
National Championship 2018 Live
National Championship Game
National Championship Game Live
CFP National Championship
ReplyDeleteGrammys
Grammys Live
Grammys 2018
Grammys 2018 Live
Grammy 2018
2018 Grammys
Grammy Awards
Grammys
Grammys Live
Grammys 2018
Grammys 2018 Live
Grammy 2018
Grammy Awards
Grammy Awards 2018
ReplyDeleteFinal Four
Final Four Live
Final Four 2018
Final Four 2018 Live
2018 Final Four
NCAA Final Four
Final Four Basketball
Final Four
Final Four Live
Final Four 2018
2018 Final Four
Final Four Basketball
ReplyDeleteMasters
The Masters
Masters 2018
Masters 2018 Live
2018 Masters
Masters Golf
Masters Tournament
The Masters
Masters 2018
Masters 2018 Live
Masters Golf
Masters Golf Live
Masters Golf 2018
Masters Tournament
ReplyDeleteHow To Watch 76ers vs heat Live Stream Free:
76ers vs heat
76ers vs heat live stream
heat vs 76ers
heat vs 76ers live
heat vs 76ers live
heat vs 76ers live stream
how to watch nba live stream
Philadelphia 76ers vs. Miami Heat
How To Watch warriors vs spurs Live Stream Free:
warriors vs spurs
warriors vs spurs live
warriors vs spurs live stream
spurs vs warriors
spurs vs warriors live
spurs vs warriors live stream
golden state warriors vs san antonio spurs
ReplyDeleteNFL Draft
NFL Draft Live
NFL Draft 2018
NFL Draft 2018 Live
2018 NFL Draft
NFL Draft
NFL Draft Live
NFL Draft 2018
NFL Draft 2018 Live
2018 NFL Draft
How To Watch champions league final live streaming 2018 HD Online:
ReplyDeletechampions league final
champions league
uefa champions league
uefa champions league 2018
uefa champions
champions league final tickets
champions league fixtures
uefa champions league final
champions league results
champions league table
champions league groups
champions league schedule
champions league winners
uefa champions league results
champions league football
champions league live
champions league draw
champions league scores
concacaf champions league
champions league live streaming
2018 uefa champions league final
uefa champions league live
watch champions league live
champions league final date
watch champions league online
watch champions league
champions league tv
champions league semi finals
champions league news
champions league games
champions league trophy
champions league final tv
buy champions league final tickets
champions league qualification
champions league final tickets price
champions league final results
champions league bracket
ReplyDeleteNBA Finals
NBA Finals Live
NBA Finals 2018
NBA Finals 2018 Live
2018 NBA Finals
NBA Finals
NBA Finals Live
NBA Finals 2018
NBA Finals
NBA Finals Live
NBA Finals 2018
NBA Finals
NBA Finals Live
NBA Finals 2018
NBA Finals 2018 Live
The US Open Tennis 2020 Live stream will be for the 140th edition of the tournament, which is set to feature many prominent names in the world of tennis.
ReplyDelete