我有一个列表视图,每行有几个图像按钮.单击列表行时,将启动新活动.由于相机布局有问题,我不得不建立自己的标签.为结果启动的活动是地图.如果我单击我的按钮启动图像预览(从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) My app shows a list of 9 categories and each category displays a Gallery-based coverflow (graciously offered by Neil Davies here) with images of the selected category.
The images are fetched from the Web, each ranging from 300K to 500K in size, and stored in an arrayList of Drawables. This data is bound to the coverflow using a BaseAdapter (code below).
Every time I exit the coverflow and go back to the list of categories, I clear the arrayList …
我目前正在开发一个讲述故事的应用程序.故事包含"场景",其中包含通过ImageViews显示的多个JPEG和PNG文件.我创建了ImageView并通过以下函数将其添加到布局中:
private ImageView newImage(Show show)
{
ImageView iv = new ImageView(this);
String filePath = comin.generateFilePath(show);
Log.i(TAG, "newImage, filePath = " + filePath + " id = " + show.id);
WeakReference<Bitmap> bmp = new WeakReference<Bitmap>(scaleBitmap(filePath)); //added 4/1/13
//Bitmap bmp = scaleBitmap(filePath);
Log.i(TAG, "newImage, width = " + bmp.get().getWidth() + ", height = " + bmp.get().getHeight());
iv.setImageBitmap(bmp.get());
iv.setScaleType(ImageView.ScaleType.FIT_XY);
iv.setId(show.id);
//set visibility
if (show.visible)
iv.setVisibility(View.VISIBLE);
else
iv.setVisibility(View.INVISIBLE);
//set dimensions
int width = (app.getWidth() * show.dimX) / 100;
int height = (app.getHeight() * show.dimY) …Run Code Online (Sandbox Code Playgroud) 由于虚拟内存堆大小有限,我遇到了内存不足的问题.
这是我从服务器获取位图的代码:
@SuppressWarnings("unchecked")
public class DrawableManager {
@SuppressWarnings("rawtypes")
private final Map drawableMap;
@SuppressWarnings("rawtypes")
private DrawableManager() {
drawableMap = new HashMap();
}
static private DrawableManager _instance;
static public DrawableManager getInstance() {
if(_instance == null) {
_instance = new DrawableManager();
}
return _instance;
}
public Bitmap fetchBitmap(final String sURL) {
if(sURL.length() == 0)
return null;
Bitmap bm = (Bitmap) drawableMap.get(sURL);
if(bm != null) {
return bm;
}
byte[] imageData = ThumbImg(sURL);
if(imageData == null)
return null;
if(imageData.length > 0) {
bm = …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习如何在网格视图中显示存储在Android手机上的所有图像(我的目标是让用户选择他们想要处理的图像).
我正在调整教程:
http://developer.android.com/resources/tutorials/views/hello-gridview.html
这样做.
上面是我修改过的ImageAdapter类的链接(我认为唯一需要更改的内容).
在其中,我没有一个整数的资源ID数组,而是有一个媒体文件位置的字符串数组,并将它们变成一个位图,如下所示:
imageView.setImageBitmap(BitmapFactory.decodeFile(picture_paths[position]));
Run Code Online (Sandbox Code Playgroud)
我通过以下方式获取文件位置:
public void populateArray(){
Log.v("Jenny","Populating array");
picture_paths = new String[getCount()];
cursor.moveToFirst();
int count = 0;
while(!cursor.isLast() ){
count ++;
picture_paths[cursor.getPosition()] = cursor.getString(0);
cursor.moveToNext();
}
}
Run Code Online (Sandbox Code Playgroud)
它就像一个宝石,只要我有少于9张图片(三列三列).
除此之外,事情因"内存不足"错误而崩溃.如果我只是按照教程使用资源图像,我可以拥有尽可能多的东西.
那么:我是否采取了错误的方式?将它作为Bitmap加载到密集型?有什么替代品?
显示存储在手机上的图像似乎是一项非常简单的基本任务.做到这一点的"正确"方法是什么,无论如何我能用这种方式工作吗?
编辑:在我的第二部手机(Galaxy)上进行测试使得工作正常(可以显示任意数量的图像,尽管有时候光标检索的文件路径是'null').在我的原始测试手机(myTouch)上,无论我如何尝试显示图像(可绘制,位图等),我都会收到内存错误.为什么我会在两部手机上获得不同的行为?
编辑:嗯,有一件事可能会发生,我的myTouch上面有更多图片?我在Galaxy上拍了几张照片,现在也出现了内存错误......网格视图不是用于显示照片(如果没有,它有什么用处?)
仍然限制在myTouch上9,但在Galaxy上可以达到11
旋转时两者都会因内存不足而崩溃(即视图重绘).(虽然没有少量的照片(可能少于6张?)
我试图修复Android摄像头意图保存图像景观时拍摄肖像问题,但遇到了dalvikvm-heap Out of memory on a 63489040-byte allocation.错误的问题.我看了一下createBitmap()引导我进入java.lang.OutOfMemoryError,但这个问题没有任何帮助.我不知道如何解决这个问题.我试着调用recycle()位图,但这不起作用.
String file = getRealPathFromURI(Uri.parse(mUriString));
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file, bounds);
BitmapFactory.Options opts = new BitmapFactory.Options();
Bitmap bm = BitmapFactory.decodeFile(file, opts);
ExifInterface exif = new ExifInterface(file);
String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL;
int rotationAngle = 0;
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotationAngle = 90;
case ExifInterface.ORIENTATION_ROTATE_180:
rotationAngle = 180;
case ExifInterface.ORIENTATION_ROTATE_270:
rotationAngle = 270; …Run Code Online (Sandbox Code Playgroud) 我在Play商店发布了我的应用程序.现在在Crashes和ANR中,我在2个设备上遇到错误(Galaxy Note3和Galaxy Note II).我不知道如何解决这些错误,这是什么类型的错误?所以请帮我解决这些错误.在其他设备上,我没有收到任何报告.
错误 -
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
at android.content.res.Resources.loadDrawable(Resources.java:3022)
at android.content.res.Resources.getDrawable(Resources.java:1586)
at android.view.View.setBackgroundResource(View.java:16120)
at com.info.laughingbuddha.Buddha4.onCreateView(Buddha4.java:21)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:244)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:572)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1259)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
Buddha4.java-
package com.info.laughingbuddha;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import …Run Code Online (Sandbox Code Playgroud)