【发布时间】:2016-02-24 07:37:57
【问题描述】:
我要制作像Retrica这样的应用程序
问题是我对图像应用了一些过滤器或效果,这会导致 java.lang.OutOfMemoryError 并需要更多时间来应用图像。
public class ImageEnhancemeane extends AppCompatActivity {
private static final int[] FROM_COLOR = new int[]{49, 179, 110};
private static final int THRESHOLD = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_enhancemeane);
ImageView imgStatus = (ImageView) findViewById(R.id.backImage);
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.testimg);
imgStatus.setImageBitmap(createSepiaToningEffect(bm, 2, 0.2, 0.5, 0.59));
}
public static Bitmap createSepiaToningEffect(Bitmap src, int depth, double red, double green, double blue) {
// image size
int width = src.getWidth();
int height = src.getHeight();
// create output bitmap
Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
// constant grayscale
final double GS_RED = 0.3;
final double GS_GREEN = 0.59;
final double GS_BLUE = 0.11;
// color information
int A, R, G, B;
int pixel;
// scan through all pixels
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
// get pixel color
pixel = src.getPixel(x, y);
// get color on each channel
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
// apply grayscale sample
B = G = R = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B);
// apply intensity level for sepid-toning on each channel
R += (depth * red);
if (R > 255) {
R = 255;
}
G += (depth * green);
if (G > 255) {
G = 255;
}
B += (depth * blue);
if (B > 255) {
B = 255;
}
// set new pixel color to output image
bmOut.setPixel(x, y, Color.argb(A, R, G, B));
}
}
src.recycle();
src = null;
// return final image
return bmOut;
}
}
这里是 createSepiaToningEffect() 方法是我对图像应用一些效果的过滤器,但它会导致 OutOfMemoryError。
我将在清单中使用 largeheap = true 解决 OutOfMemoryError,但我想要更好的解决方案。
当我调用过滤器并对图像应用一些效果时,这将需要一些时间。
请给出一些固体溶液。
【问题讨论】:
-
你能请任何人帮助我吗
标签: android performance android-layout image-processing out-of-memory