我正在使用位图.当代码运行时,它显示内存不足错误.如何避免错误.我的代码如下.提前致谢.
Bitmap myBitmap = Image.decodeSampledBitmapFromUri(path, 250, 500);
img_cook[index].setImageBitmap(myBitmap);
public static Bitmap decodeSampledBitmapFromUr(String path, int reqWidth,
int reqHeight) {
Bitmap bm = null;
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeFile(path, options);
return bm;
}
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) …Run Code Online (Sandbox Code Playgroud) 如何在Android中使用视频视图来避免或清除手机屏幕的背景?
[1] :( http://i.stack.imgur.com/0pl9W.png)
View.OnClickListener handleOnClickVideo(final ImageView button1) {
return new View.OnClickListener() {
public void onClick(View v) {
try {
Constant.database = new MyHelper(getApplicationContext());
Constant.sqldb = Constant.database.getReadableDatabase();
imageShowed.setVisibility(View.GONE);
videoShowed.setVisibility(View.VISIBLE);
mVideoView.setBackgroundColor(Color.BLACK);
bar.show();
int newVideoId = button1.getId();
Constant.database.getContentValues(newVideoId);
String getVideo = "https://whootin.s3.amazonaws.com/uploads/upload/21e0b4df-120d-4c9f-ad4a-b475bb844b48/Homemade%20Steak%20Fajitas%20Recipe%20-%20Laura%20Vitale%20-%20Laura%20in%20the%20.mp4?AWSAccessKeyId=AKIAJF5QHW2P5ZLAGVDQ&Signature=EGU5xUP3E8QpkTrG71dr0MvR2hQ%3D&Expires=1381916425";//GetSet.getVideo();
Log.d("video", getVideo);
mVideoView.setSoundEffectsEnabled(true);
mVideoView.setDrawingCacheEnabled(true);
mediaController.setAnchorView(mVideoView);
mVideoView.setVideoURI(Uri.parse(getVideo));
mVideoView.setKeepScreenOn(true);
mVideoView.setMediaController(mediaController);
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(PreparedListener);
Constant.database.close();
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
bar.dismiss();
}
}
};
}
Run Code Online (Sandbox Code Playgroud)
我附上了我的代码.
android ×2