У меня есть следующий код для сохранения изображения в директорию кеша моего приложения. Метод вызывается в отдельном Runnable()
, который, как я надеялся, ускорит работу приложения. В настоящее время сжатие растрового изображения очень дорого на процессоре и приводит к очень медленной остальной части приложения. Как я могу ускорить это?
public void combineImages(Bitmap bmp, int count, int count2){
Bitmap bottomImage = bmp.copy(Config.RGB_565, true);
float width = bmp.getWidth();
float height = bmp.getHeight();
bmp.recycle();
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image1);
Bitmap topImage = myBitmap.copy(Config.ARGB_4444, true);
myBitmap.recycle();
myBitmap = null;
Canvas comboImage = new Canvas(bottomImage);
// Then draw the second on top of that
comboImage.drawBitmap(topImage, (width / 2) - 200, (height / 2) - 160, null);
topImage.recycle();
topImage = null;
// bottomImage is now a composite of the two.
// To write the file out to the Cache:
OutputStream os = null;
try {
os = new FileOutputStream(getApplicationContext().getCacheDir() + "/" + path);
bottomImage.compress(CompressFormat.PNG, 50, os); //Here it is most expensive and what slows the app down
} catch (IOException e) {
e.printStackTrace();
}
}