80,348
社区成员
发帖
与我相关
我的任务
分享
private Bitmap makeMiniThumbBitmap(int width, int height, ImageManager.IImageList images) {
int count = images.getCount();
// We draw three different version of the folder image depending on the number of images in the folder.
// For a single image, that image draws over the whole folder.
// For two or three images, we draw the two most recent photos.
// For four or more images, we draw four photos.
final int padding = 4;
int imageWidth = width;
int imageHeight = height;
int offsetWidth = 0;
int offsetHeight = 0;
imageWidth = (imageWidth - padding) / 2; // 2 here because we show two images
imageHeight = (imageHeight - padding) / 2; // per row and column
final Paint p = new Paint();
final Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas c = new Canvas(b);
final Matrix m = new Matrix();
// draw the whole canvas as transparent
p.setColor(0x00000000);
c.drawPaint(p);
// draw the mask normally
p.setColor(0xFFFFFFFF);
mFrameGalleryMask.setBounds(0, 0, width, height);
mFrameGalleryMask.draw(c);
Paint pdpaint = new Paint();
pdpaint.setXfermode(new android.graphics.PorterDuffXfermode(
android.graphics.PorterDuff.Mode.SRC_IN));
pdpaint.setStyle(Paint.Style.FILL);
c.drawRect(0, 0, width, height, pdpaint);
for (int i = 0; i < 4; i++) {
if (mPausing) {
return null;
}
Bitmap temp = null;
ImageManager.IImage image = i < count ? images.getImageAt(i) : null;
if (image != null) {
temp = image.miniThumbBitmap();
}
if (temp != null) {
if (ImageManager.isVideo(image)) {
Bitmap newMap = temp.copy(temp.getConfig(), true);
Canvas overlayCanvas = new Canvas(newMap);
int overlayWidth = mVideoOverlay.getIntrinsicWidth();
int overlayHeight = mVideoOverlay.getIntrinsicHeight();
int left = (newMap.getWidth() - overlayWidth) / 2;
int top = (newMap.getHeight() - overlayHeight) / 2;
Rect newBounds = new Rect(left, top, left + overlayWidth, top + overlayHeight);
mVideoOverlay.setBounds(newBounds);
mVideoOverlay.draw(overlayCanvas);
temp.recycle();
temp = newMap;
}
Bitmap temp2 = ImageLoader.transform(m, temp, imageWidth, imageHeight, true);
if (temp2 != temp)
temp.recycle();
temp = temp2;
}
Bitmap thumb = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888);
Canvas tempCanvas = new Canvas(thumb);
if (temp != null)
tempCanvas.drawBitmap(temp, new Matrix(), new Paint());
mCellOutline.setBounds(0, 0, imageWidth, imageHeight);
mCellOutline.draw(tempCanvas);
placeImage(thumb, c, pdpaint, imageWidth, padding, imageHeight, padding, offsetWidth, offsetHeight, i);
thumb.recycle();
if (temp != null)
temp.recycle();
}
return b;
}