本文整理汇总了Java中android.media.ThumbnailUtils.extractThumbnail方法的典型用法代码示例。如果您正苦于以下问题:Java ThumbnailUtils.extractThumbnail方法的具体用法?Java ThumbnailUtils.extractThumbnail怎么用?Java ThumbnailUtils.extractThumbnail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.ThumbnailUtils
的用法示例。
在下文中一共展示了ThumbnailUtils.extractThumbnail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPixels
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
public static float[] getPixels(Bitmap bitmap, int[] intValues, float[] floatValues) {
if (bitmap.getWidth() != IMAGE_SIZE || bitmap.getHeight() != IMAGE_SIZE) {
// rescale the bitmap if needed
bitmap = ThumbnailUtils.extractThumbnail(bitmap, IMAGE_SIZE, IMAGE_SIZE);
}
bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
// Preprocess the image data from 0-255 int to normalized float based
// on the provided parameters.
for (int i = 0; i < intValues.length; ++i) {
final int val = intValues[i];
floatValues[i * 3] = (((val >> 16) & 0xFF) - IMAGE_MEAN) / IMAGE_STD;
floatValues[i * 3 + 1] = (((val >> 8) & 0xFF) - IMAGE_MEAN) / IMAGE_STD;
floatValues[i * 3 + 2] = ((val & 0xFF) - IMAGE_MEAN) / IMAGE_STD;
}
return floatValues;
}
示例2: onDraw
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas canvas) {
if (bitmap != null) {
int size = Math.min(canvas.getWidth(), canvas.getHeight());
if (size != this.size) {
this.size = size;
bitmap = ThumbnailUtils.extractThumbnail(bitmap, size, size);
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
roundedBitmapDrawable.setCornerRadius(size / 2);
roundedBitmapDrawable.setAntiAlias(true);
bitmap = ImageUtils.drawableToBitmap(roundedBitmapDrawable);
}
canvas.drawBitmap(bitmap, 0, 0, paint);
}
}
示例3: turnBlackWhite
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
/**
* 将彩色图转换为纯黑白二色
*
* @param origin bitmap
* @return Bitmap
*/
@SuppressWarnings("NumericOverflow")
public static Bitmap turnBlackWhite(Bitmap origin) {
int w = origin.getWidth();
int h = origin.getHeight();
int[] pixels = new int[w * h];
origin.getPixels(pixels, 0, w, 0, 0, w, h);
int alpha = 0xFF << 24;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
int gray = pixels[w * i + j];
int red = ((gray & 0x00FF0000) >> 16);
int green = ((gray & 0x000FF00) >> 8);
int blue = (gray & 0x000000FF);
gray = (int) (red * 0.3 + green * 0.59 + blue * 0.11);
gray = alpha | (gray << 16) | (gray << 8) | gray;
pixels[w * i + j] = gray;
}
}
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, w, 0, 0, w, h);
return ThumbnailUtils.extractThumbnail(bitmap, w, h);
}
示例4: getPixels
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
public static float[] getPixels(Bitmap bitmap) {
if (bitmap.getWidth() != IMAGE_SIZE || bitmap.getHeight() != IMAGE_SIZE) {
// rescale the bitmap if needed
bitmap = ThumbnailUtils.extractThumbnail(bitmap, IMAGE_SIZE, IMAGE_SIZE);
}
int[] intValues = new int[IMAGE_SIZE * IMAGE_SIZE];
bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
float[] floatValues = new float[IMAGE_SIZE * IMAGE_SIZE * 3];
// Preprocess the image data from 0-255 int to normalized float based
// on the provided parameters.
for (int i = 0; i < intValues.length; ++i) {
final int val = intValues[i];
floatValues[i * 3] = (((val >> 16) & 0xFF) - IMAGE_MEAN) / IMAGE_STD;
floatValues[i * 3 + 1] = (((val >> 8) & 0xFF) - IMAGE_MEAN) / IMAGE_STD;
floatValues[i * 3 + 2] = ((val & 0xFF) - IMAGE_MEAN) / IMAGE_STD;
}
return floatValues;
}
示例5: getThumbFromThumbPath
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
public static Bitmap getThumbFromThumbPath(Context ctx, String filePath, int kind) {
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeFile(filePath);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, 80, 80,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
} catch (Exception e) {
e.printStackTrace();
return null;
} catch (OutOfMemoryError o) {
System.gc();
try {
bitmap = createImageThumbnailThrowErrorOrException(ctx,
filePath, kind);
return bitmap;
} catch (Throwable t) {
t.printStackTrace();
return null;
}
}
return bitmap;
}
示例6: getImageThumbnail
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
public static Bitmap getImageThumbnail(String imagePath, int width, int height) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inJustDecodeBounds = false;
int outWidth = options.outWidth;
int outHeight = options.outHeight;
int w = outWidth / width;
int h = outHeight / height;
int inSampleSize;
if (w < h) {
inSampleSize = w;
} else {
inSampleSize = h;
}
if (inSampleSize <= 0) {
inSampleSize = 1;
}
options.inSampleSize = inSampleSize;
Bitmap bitmap = BitmapFactory.decodeFile(imagePath, options);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
示例7: setImageBitmap
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
@Override
public void setImageBitmap(Bitmap bm) {
super.setImageBitmap(bm);
if (bm == null) {
mPaint.reset();
mPaint.setColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
invalidate();
return;
} else {
mPaint.setColor(ContextCompat.getColor(getContext(), android.R.color.white));
}
Bitmap centerCroppedBitmap = ThumbnailUtils.extractThumbnail(bm, mSide, mSide);
BitmapShader shader = new BitmapShader(centerCroppedBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mPaint.setShader(shader);
}
示例8: getPictureImage
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
/**
* 获取图片缩略图
*/
public static Bitmap getPictureImage(String urlPath) {
Bitmap bitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
bitmap = BitmapFactory.decodeFile(urlPath, options);
options.inJustDecodeBounds = false;
int h = options.outHeight;
int w = options.outWidth;
int beWidth = w / 100;
int beHeight = h / 80;
int be = 1;
if (beWidth < beHeight) {
be = beWidth;
} else {
be = beHeight;
}
if (be <= 0) {
be = 1;
}
options.inSampleSize = be;
bitmap = BitmapFactory.decodeFile(urlPath, options);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, 100, 80,ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
示例9: doInBackground
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
@Override
protected Object doInBackground(FileItem... params) {
Bitmap bitmap = null;
// 鑾峰彇瑙嗛鐨勭缉鐣ュ浘
FileItem item = params[0];
bitmap = ThumbnailUtils.createVideoThumbnail(item.getFilePath(),
Thumbnails.MICRO_KIND);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
if (bitmap != null) {
item.setIcon(bitmap);
publishProgress();
return bitmap;
} else {
return null;
}
}
示例10: getThumbnail
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
/**
* Creates a thumbnail of requested size by doing a first sampled decoding of the bitmap to optimize memory
*/
public static Bitmap getThumbnail(Context mContext, Uri uri, int reqWidth, int reqHeight) {
Bitmap srcBmp = BitmapUtils.decodeSampledFromUri(mContext, uri, reqWidth, reqHeight);
// If picture is smaller than required thumbnail
Bitmap dstBmp;
if (srcBmp.getWidth() < reqWidth && srcBmp.getHeight() < reqHeight) {
dstBmp = ThumbnailUtils.extractThumbnail(srcBmp, reqWidth, reqHeight);
// Otherwise the ratio between measures is calculated to fit requested thumbnail's one
} else {
// Cropping
int x = 0, y = 0, width = srcBmp.getWidth(), height = srcBmp.getHeight();
float ratio = ((float) reqWidth / (float) reqHeight) * ((float) srcBmp.getHeight() / (float) srcBmp
.getWidth());
if (ratio < 1) {
x = (int) (srcBmp.getWidth() - srcBmp.getWidth() * ratio) / 2;
width = (int) (srcBmp.getWidth() * ratio);
} else {
y = (int) (srcBmp.getHeight() - srcBmp.getHeight() / ratio) / 2;
height = (int) (srcBmp.getHeight() / ratio);
}
dstBmp = Bitmap.createBitmap(srcBmp, x, y, width, height);
}
return dstBmp;
}
示例11: decodeSampledBitmap
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
/**
* Creates and returns a Bitmap of the image at the given filepath, scaled down to fit the area the Bitmap will be displayed in
* @param image_file_path location of the image to sample
* @param reqWidth width at which the resultant Bitmap will be displayed
* @param reqHeight height at which the resultant Bitmap will be displayed
* @return a Bitmap large enough to cover the given area
*/
public static Bitmap decodeSampledBitmap(String image_file_path, int reqWidth, int reqHeight) {
Log.v(TAG, "creating bitmap for " + image_file_path);
long start = android.os.SystemClock.uptimeMillis();
final BitmapFactory.Options options = getBitmapBounds(image_file_path);
options.inSampleSize = calculateInSampleSize(options.outWidth, options.outHeight, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
Bitmap sampled = BitmapFactory.decodeFile(image_file_path, options);
long sampled_time = android.os.SystemClock.uptimeMillis();
Log.v(TAG, "created sampled bitmap for " + image_file_path + ", took " + (sampled_time-start) + "ms");
Bitmap oriented = fixOrientation(sampled, image_file_path);
long orientation_fixed_time = android.os.SystemClock.uptimeMillis();
Log.v(TAG, "fixed orientation for " + image_file_path + ", took " + (orientation_fixed_time-sampled_time) + "ms");
Bitmap final_bitmap = ThumbnailUtils.extractThumbnail(oriented, reqWidth, reqHeight);
long end = android.os.SystemClock.uptimeMillis();
Log.v(TAG, "finished resizing bitmap for " + image_file_path + ", took " + (end-orientation_fixed_time) + "ms");
Log.v(TAG, "finished creating bitmap for " + image_file_path + ", took " + (end-start) + "ms");
return final_bitmap;
}
示例12: getVideoThumbnail
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
/**
* 获取视频图像
*
* @param videoPath
* @return
*/
public static Bitmap getVideoThumbnail(String videoPath) {
Bitmap bitmap = null;
bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, Thumbnails.MINI_KIND);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, 100, 100, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
示例13: createImageThumbnail
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
/**
* Create a thumbnail with rounded corners from an image file.
*
* @param file The input file
* @param width The thumbnail width
* @param height The thumbnail height
* @return The generated thumbnail
*/
public static Bitmap createImageThumbnail(File file, int width, int height) {
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
if (bitmap == null) {
return (null);
}
Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap, width, height);
if (thumbnail == null) {
return (null);
}
Bitmap out = Bitmap.createBitmap(thumbnail.getWidth(), thumbnail.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(out);
Paint paint = new Paint();
paint.setAntiAlias(true);
RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
canvas.drawARGB(0, 0, 0, 0);
canvas.drawRoundRect(rect, 12.0f, 12.0f, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(thumbnail, 0, 0, paint);
return (out);
}
示例14: doInBackground
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
@Override
protected Bitmap doInBackground(Void... params) {
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPurgeable = true; // GC可能にする
opt.inSampleSize = 2;
// ContentResolver resolver = activity.getContentResolver();
// Cursor cursor = resolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Images.ImageColumns.DATA + " = ?", new String[]{filePath}, null);
// if(cursor.moveToFirst())
// {
// // サムネイルの取得
// long id = cursor.getLong(cursor.getColumnIndex("_id"));
// return MediaStore.Images.Thumbnails.getThumbnail(resolver, id, MediaStore.Images.Thumbnails.MICRO_KIND, opt);
// }
// return null;
return ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(filePath), 100, 100, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
}
示例15: createVideoThumbnail
import android.media.ThumbnailUtils; //导入方法依赖的package包/类
/**
* Draws a watermark on ImageView to highlight videos
*
* @param bmp
* @param overlay
* @return
*/
public static Bitmap createVideoThumbnail(Context mContext, Bitmap video, int width, int height) {
video = ThumbnailUtils.extractThumbnail(video, width, height);
Bitmap mark = ThumbnailUtils.extractThumbnail(
BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.play_no_bg), width, height);
// Bitmap thumbnail = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Bitmap thumbnail = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(thumbnail);
// Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
// canvas.drawBitmap(checkIfBroken(mContext, video, height, height), 0, 0, null);
canvas.drawBitmap(video, 0, 0, null);
canvas.drawBitmap(mark, 0, 0, null);
return thumbnail;
}