我有一个列表视图,每行有几个图像按钮.单击列表行时,将启动新活动.由于相机布局有问题,我不得不建立自己的标签.为结果启动的活动是地图.如果我单击我的按钮启动图像预览(从SD卡加载图像),应用程序将从活动返回到活动返回到listview结果处理程序以重新启动我的新活动,这只是一个图像小部件.
列表视图上的图像预览正在使用光标和ListAdapter.这使得它非常简单,但我不确定如何放置一个经过调整大小的图像(即小的像素大小不像动态src图像按钮那样.所以我只是调整了从手机摄像头下来的图像.
问题是当我试图返回并重新启动第二个活动时,我收到内存不足错误.
这是更好的,因为我还需要对每行中的小部件/元素的属性进行一些更改,因为焦点问题我无法选择带触摸屏的行.(我可以用滚球.)
一旦我在列表视图上禁用了图像,它再次正常工作.
仅供参考:这就是我的做法:
String[] from = new String[] { DBHelper.KEY_BUSINESSNAME,DBHelper.KEY_ADDRESS,DBHelper.KEY_CITY,DBHelper.KEY_GPSLONG,DBHelper.KEY_GPSLAT,DBHelper.KEY_IMAGEFILENAME + ""};
int[] to = new int[] {R.id.businessname,R.id.address,R.id.city,R.id.gpslong,R.id.gpslat,R.id.imagefilename };
notes = new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
Run Code Online (Sandbox Code Playgroud)
哪里R.id.imagefilename是ButtonImage.
这是我的LogCat:
01-25 05:05:49.877: ERROR/dalvikvm-heap(3896): 6291456-byte external allocation too large for this process.
01-25 05:05:49.877: ERROR/(3896): VM wont let us allocate 6291456 bytes
01-25 05:05:49.877: ERROR/AndroidRuntime(3896): Uncaught handler: thread main exiting due to …Run Code Online (Sandbox Code Playgroud) 我知道有很多关于android位图图像内存的讨论,但我想知道是否有人可以向我解释..
目前在我的应用程序中,我有一个列出图像缩略图(低质量)的活动,当我单击图像时,它会打开一个新活动以全屏查看图像.在我的第二个活动课中,我有:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
bm = BitmapFactory.decodeFile(myImagePath, options);
Run Code Online (Sandbox Code Playgroud)
然后我把它放到ImageView中显示它.这可以使我的图像显示其全部质量.但是,如果我再次单击然后再单击以查看该图像(并重复此次6次)..第6次打开图像(activity2)时出现内存不足错误,说堆大小= 6919KB,分配= 3125KB,位图大小= 25848KB!
位图大小如何大?我假设它可能一直在创建新的实例,所以我决定在我的第二个活动中放一个方法来按下后退键.在这个方法中我设置了我的bitmap = null并且也做了System.gc()清除垃圾收集器,但这没有解决问题.在第6次点击缩略图以全分辨率查看图像时,我仍然会出现内存不足错误
有谁能解释为什么?谢谢
我有两个活动:MainActivity和Activity2。
MainActivity 只是通过 Intent 打开秒一。
要返回MainActivity从Activity2我按下“返回”按钮。
当我执行这些步骤时,应用程序崩溃:
MainActivity出现Activity2出现MainActivity出现Intent:由于此错误,我的应用程序崩溃:
IllegalArgumentException:无法绘制回收位图
主活动.java:
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
Activity2.java:
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
protected void onDestroy() {
super.onDestroy();
for(Map.Entry<Integer, ImageView> entry : mapImageViews.entrySet()) {
ImageView imageView = entry.getValue();
Drawable drawable = imageView.getDrawable();
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
if(bitmap != …Run Code Online (Sandbox Code Playgroud) 我必须从许多图像中导入大量的图像裁剪,这些图像都已准备好存储在我的数据库中.我每次尝试使用语句并处理我的位图对象.但我仍然得到一个内存溢出异常,我的系统内存不足.
以下是我正在做的一些示例代码.
public void CropImage(List<ImageClass> data)
{
foreach (var obj in data)
{
//I have a data base method that returns a data object that
//contains the file bytes of the image id in data: 'file'
//My List<ImageClass> data contains an ID of the original image
//start x,y coords for the upper left corner of the rectangle,
//and the width and height of the rectangle.
Image img = Image.FromStream(new MemoryStream(file.Data));
Bitmap bmp = new Bitmap((Bitmap)img);
Rectangle cropArea = new Rectangle(obj.x_coordinate, …Run Code Online (Sandbox Code Playgroud) 我不断尝试OutOfMemory异常尝试解码我的Android应用程序中的相机图像.处理这个问题有很多问题,但是我的情况特别奇怪,因为即使只是试图获得边界,我也会得到异常options.inJustDecodeBounds=true.
这是启动相机的代码:
protected void takePicture() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = new File(IMAGE_PATH, "camera.jpg");
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
startActivityForResult(takePictureIntent, 0);
}
Run Code Online (Sandbox Code Playgroud)
这是触发异常的代码:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK ) {
String rawImageName = new String(IMAGE_PATH + "/camera.jpg");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(rawImageName); // The exception is thrown here
.
.
.
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用非常高的采样率解码图像,但我仍然得到相同的异常:
options.inSampleSize = 20;
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap photo = …Run Code Online (Sandbox Code Playgroud)