带位图的OOM在android studio中创建交互式地图

时间:2019-02-22 23:41:42

标签: android bitmap out-of-memory android-glide

我有4张图像,显示了建筑物的不同楼层布局,并显示了每个房间的位置。根据{{​​3}}教程,还有4个相应的颜色(热点)不可见图像,当触摸这些图像时,它们会返回像素颜色。另外,其他4个ImageView显示了一个覆盖层,该覆盖层显示了一个房间(图像的尺寸与其他房间相同,但其余图像是透明的)。根据触摸颜色将其设置为其他可绘制对象 即每种颜色代表一个房间,当点击该颜色时应突出显示该房间

图像位于View Pager中,因此每个页面都会用3个ImageView(floorImage,hotspotImage,overlayImage)来放大布局

单击许多不同的房间时,出现内存不足错误 E / dalvikvm-heap:2587740字节分配上的内存不足。 我使用Glide将视图传呼器中的不可见图像设置在某个位置:

Glide.with(ctx)
            .asBitmap()
            .load(hotspot_resources[position])
            .into(hotspotView);

我对其他图像使用相同的代码(但没有.asBitmap())。然后我得到位图,并用它来检索像素坐标:

Matrix inverse = new Matrix();
hotspotImage.getImageMatrix().invert(inverse);
float[] touchPoint = new float[] {x, y};
inverse.mapPoints(touchPoint);
int xCoord = (int)touchPoint[0];
int yCoord = (int)touchPoint[1];
Bitmap hotspots = ((BitmapDrawable)hotspotImage.getDrawable()).getBitmap();
return hotspots.getPixel(xCoord, yCoord);

是什么原因导致OOM错误,经常将使用位图或其他Drawable的方法加载到同一ImageView中?

0 个答案:

没有答案