1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-06 03:50:19 +02:00

introduced BitmapImageData

This commit is contained in:
Nikolay Pultsin 2014-06-29 20:35:02 +01:00
parent d576eb3691
commit 5b8dec9ffd
2 changed files with 51 additions and 2 deletions

View file

@ -0,0 +1,50 @@
/*
* Copyright (C) 2007-2014 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.zlibrary.ui.android.image;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
final class BitmapImageData extends ZLAndroidImageData {
static BitmapImageData get(ZLBitmapImage image) {
final Bitmap bitmap = image.getBitmap();
return bitmap != null ? new BitmapImageData(bitmap) : null;
}
private final Bitmap myBitmap;
private BitmapImageData(Bitmap bitmap) {
myBitmap = bitmap;
}
protected Bitmap decodeWithOptions(BitmapFactory.Options options) {
final int scaleFactor = options.inSampleSize;
if (scaleFactor <= 1) {
return myBitmap;
}
try {
return Bitmap.createScaledBitmap(
myBitmap, myBitmap.getWidth() / scaleFactor, myBitmap.getHeight() / scaleFactor, false
);
} catch (Exception e) {
return null;
}
}
}

View file

@ -28,8 +28,7 @@ public final class ZLAndroidImageManager extends ZLImageManager {
if (image instanceof ZLStreamImage) {
return new InputStreamImageData((ZLStreamImage)image);
} else if (image instanceof ZLBitmapImage) {
// TODO: implement
return null;
return BitmapImageData.get((ZLBitmapImage)image);
} else if (image instanceof ZLImageProxy) {
return getImageData(((ZLImageProxy)image).getRealImage());
} else {