I want to combine many small bitmaps which are contained in ArrayList to one large bitmap.
However, I don't know why the large bitmap is looped. It means it seems to copy only the first element in the array. I tried to draw each small bitmap in the array to test and it works fine, but when I run the loop like the below code, it goes wrong.
In addiditon, when I add the bmp.recycle()
and bmp = null
, it causes the error "trying to use a recycled bitmap". I don't understand why the error happens.
Can you help me, please, thanks!
public static Bitmap getBitmapForVisibleRegion(WebView webview) {
Bitmap returnedBitmap = null;
webview.setDrawingCacheEnabled(true);
returnedBitmap = Bitmap.createBitmap(webview.getDrawingCache());
webview.setDrawingCacheEnabled(false);
return returnedBitmap;
}
public void CombineBitmap(){
ArrayList<Bitmap> bmps = new ArrayList<Bitmap>();
for (int i = 0; i < webView.getWidth; i+=needToCapture){
bmps.add(getBitmapForVisibleRegion(webView));
webView.scrollBy(needToCapture, 0);
}
Bitmap bigbitmap = Bitmap.createBitmap(largeBitmapWidth, largeBitmapHeight, Bitmap.Config.ARGB_8888);
Canvas bigcanvas = new Canvas(bigbitmap);
Paint paint = new Paint();
int iWidth = 0;
for (int i = 0; i < bmps.size(); i++) {
Bitmap bmp = bmps.get(i);
bigcanvas.drawBitmap(bmp, iWidth , 0, paint);
iWidth +=bmp.getWidth();
bmp.recycle();
bmp=null;
}
}