use of android.graphics.BitmapFactory in project platform_frameworks_base by android.
the class CodecTest method getThumbnail.
//Test for mediaMeta Data Thumbnail
public static boolean getThumbnail(String filePath, String goldenPath) {
Log.v(TAG, "getThumbnail - " + filePath);
int goldenHeight = 0;
int goldenWidth = 0;
int outputWidth = 0;
int outputHeight = 0;
//This test is only for the short media file
try {
BitmapFactory mBitmapFactory = new BitmapFactory();
MediaMetadataRetriever mMediaMetadataRetriever = new MediaMetadataRetriever();
try {
mMediaMetadataRetriever.setDataSource(filePath);
} catch (Exception e) {
e.printStackTrace();
return false;
}
Bitmap outThumbnail = mMediaMetadataRetriever.getFrameAtTime(-1);
//Verify the thumbnail
Bitmap goldenBitmap = mBitmapFactory.decodeFile(goldenPath);
outputWidth = outThumbnail.getWidth();
outputHeight = outThumbnail.getHeight();
goldenHeight = goldenBitmap.getHeight();
goldenWidth = goldenBitmap.getWidth();
//check the image dimension
if ((outputWidth != goldenWidth) || (outputHeight != goldenHeight))
return false;
// Check half line of pixel
int x = goldenHeight / 2;
for (int j = 1; j < goldenWidth / 2; j++) {
if (goldenBitmap.getPixel(x, j) != outThumbnail.getPixel(x, j)) {
Log.v(TAG, "pixel = " + goldenBitmap.getPixel(x, j));
return false;
}
}
} catch (Exception e) {
Log.v(TAG, e.toString());
return false;
}
return true;
}
use of android.graphics.BitmapFactory in project Lazy by l123456789jy.
the class BitmapUtil method safeDecodeStream.
/**
* A safer decodeStream method
* rather than the one of {@link BitmapFactory}
* which will be easy to get OutOfMemory Exception
* while loading a big image file.
*
* @param uri 压缩相册返回的照片
* @return
* @throws FileNotFoundException
*/
public static Bitmap safeDecodeStream(Uri uri, int targetWidth, int targetHeight, Context mContext) throws FileNotFoundException {
BitmapFactory.Options options = new BitmapFactory.Options();
android.content.ContentResolver resolver = mContext.getContentResolver();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new BufferedInputStream(resolver.openInputStream(uri), 16 * 1024), null, options);
// 得到图片的宽度、高度;
float imgWidth = options.outWidth;
float imgHeight = options.outHeight;
// 分别计算图片宽度、高度与目标宽度、高度的比例;取大于等于该比例的最小整数;
int widthRatio = (int) Math.ceil(imgWidth / (float) targetWidth);
int heightRatio = (int) Math.ceil(imgHeight / (float) targetHeight);
options.inSampleSize = 1;
if (widthRatio > 1 || widthRatio > 1) {
if (widthRatio > heightRatio) {
options.inSampleSize = widthRatio;
} else {
options.inSampleSize = heightRatio;
}
}
// 设置好缩放比例后,加载图片进内容;
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(new BufferedInputStream(resolver.openInputStream(uri), 16 * 1024), null, options);
}
use of android.graphics.BitmapFactory in project android_frameworks_base by DirtyUnicorns.
the class CodecTest method getThumbnail.
//Test for mediaMeta Data Thumbnail
public static boolean getThumbnail(String filePath, String goldenPath) {
Log.v(TAG, "getThumbnail - " + filePath);
int goldenHeight = 0;
int goldenWidth = 0;
int outputWidth = 0;
int outputHeight = 0;
//This test is only for the short media file
try {
BitmapFactory mBitmapFactory = new BitmapFactory();
MediaMetadataRetriever mMediaMetadataRetriever = new MediaMetadataRetriever();
try {
mMediaMetadataRetriever.setDataSource(filePath);
} catch (Exception e) {
e.printStackTrace();
return false;
}
Bitmap outThumbnail = mMediaMetadataRetriever.getFrameAtTime(-1);
//Verify the thumbnail
Bitmap goldenBitmap = mBitmapFactory.decodeFile(goldenPath);
outputWidth = outThumbnail.getWidth();
outputHeight = outThumbnail.getHeight();
goldenHeight = goldenBitmap.getHeight();
goldenWidth = goldenBitmap.getWidth();
//check the image dimension
if ((outputWidth != goldenWidth) || (outputHeight != goldenHeight))
return false;
// Check half line of pixel
int x = goldenHeight / 2;
for (int j = 1; j < goldenWidth / 2; j++) {
if (goldenBitmap.getPixel(x, j) != outThumbnail.getPixel(x, j)) {
Log.v(TAG, "pixel = " + goldenBitmap.getPixel(x, j));
return false;
}
}
} catch (Exception e) {
Log.v(TAG, e.toString());
return false;
}
return true;
}
use of android.graphics.BitmapFactory in project android_frameworks_base by ParanoidAndroid.
the class CodecTest method getThumbnail.
//Test for mediaMeta Data Thumbnail
public static boolean getThumbnail(String filePath, String goldenPath) {
Log.v(TAG, "getThumbnail - " + filePath);
int goldenHeight = 0;
int goldenWidth = 0;
int outputWidth = 0;
int outputHeight = 0;
//This test is only for the short media file
try {
BitmapFactory mBitmapFactory = new BitmapFactory();
MediaMetadataRetriever mMediaMetadataRetriever = new MediaMetadataRetriever();
try {
mMediaMetadataRetriever.setDataSource(filePath);
} catch (Exception e) {
e.printStackTrace();
return false;
}
Bitmap outThumbnail = mMediaMetadataRetriever.getFrameAtTime(-1);
//Verify the thumbnail
Bitmap goldenBitmap = mBitmapFactory.decodeFile(goldenPath);
outputWidth = outThumbnail.getWidth();
outputHeight = outThumbnail.getHeight();
goldenHeight = goldenBitmap.getHeight();
goldenWidth = goldenBitmap.getWidth();
//check the image dimension
if ((outputWidth != goldenWidth) || (outputHeight != goldenHeight))
return false;
// Check half line of pixel
int x = goldenHeight / 2;
for (int j = 1; j < goldenWidth / 2; j++) {
if (goldenBitmap.getPixel(x, j) != outThumbnail.getPixel(x, j)) {
Log.v(TAG, "pixel = " + goldenBitmap.getPixel(x, j));
return false;
}
}
} catch (Exception e) {
Log.v(TAG, e.toString());
return false;
}
return true;
}
use of android.graphics.BitmapFactory in project android-gltron by Chluverman.
the class GLTexture method loadTexture.
// Will load a texture out of a drawable resource file, and return an OpenGL texture ID:
private void loadTexture(GL10 gl, Context context, int resource) {
// In which ID will we be storing this texture?
gl.glGenTextures(1, _texID, 0);
// We need to flip the textures vertically:
Matrix flip = new Matrix();
flip.postScale(1f, -1f);
// This will tell the BitmapFactory to not scale based on the device's pixel density:
// (Thanks to Matthew Marshall for this bit)
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
// Load up, and flip the texture:
Bitmap temp = BitmapFactory.decodeResource(context.getResources(), resource, opts);
Bitmap bmp = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), flip, true);
temp.recycle();
gl.glBindTexture(GL10.GL_TEXTURE_2D, _texID[0]);
// Set all of our texture parameters:
if (boGenMipMap) {
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
} else {
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
}
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, WrapS);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, WrapT);
DebugType = GLUtils.getInternalFormat(bmp);
// Generate, and load up all of the mipmaps:
if (boGenMipMap) {
for (int level = 0, height = bmp.getHeight(), width = bmp.getWidth(); true; level++) {
// Push the bitmap onto the GPU:
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bmp, 0);
// We need to stop when the texture is 1x1:
if (height == 1 && width == 1)
break;
// Resize, and let's go again:
width >>= 1;
height >>= 1;
if (width < 1)
width = 1;
if (height < 1)
height = 1;
Bitmap bmp2 = Bitmap.createScaledBitmap(bmp, width, height, true);
bmp.recycle();
bmp = bmp2;
}
} else {
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
}
bmp.recycle();
}
Aggregations