本文整理汇总了Java中android.media.ThumbnailUtils类的典型用法代码示例。如果您正苦于以下问题:Java ThumbnailUtils类的具体用法?Java ThumbnailUtils怎么用?Java ThumbnailUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThumbnailUtils类属于android.media包,在下文中一共展示了ThumbnailUtils类的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: doInBackground
import android.media.ThumbnailUtils; //导入依赖的package包/类
@Override
protected Bitmap doInBackground(Void... params) {
Bitmap bitmap = null;
try {
bitmap = ThumbnailUtils.createVideoThumbnail(mImageKey, Thumbnails.FULL_SCREEN_KIND);
if (bitmap != null) {
bitmap = Bitmap.createScaledBitmap(bitmap, mMaxWidth, mMaxWidth, false);
addBitmapToCache(mImageKey, bitmap);
return bitmap;
}
return null;
} catch (Exception e) {
if (e != null) {
e.printStackTrace();
}
return null;
}
}
示例3: setUp
import android.media.ThumbnailUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mExecutor = new TestExecutorService(new FakeClock());
mLocalVideoThumbnailProducer = new LocalVideoThumbnailProducer(
mExecutor,
RuntimeEnvironment.application.getContentResolver());
mFile = new File(RuntimeEnvironment.application.getExternalFilesDir(null), TEST_FILENAME);
mockStatic(ThumbnailUtils.class);
mProducerContext = new SettableProducerContext(
mImageRequest,
mRequestId,
mProducerListener,
mock(Object.class),
ImageRequest.RequestLevel.FULL_FETCH,
false,
false,
Priority.MEDIUM);
when(mImageRequest.getSourceFile()).thenReturn(mFile);
}
示例4: testLocalVideoMicroThumbnailReturnsNull
import android.media.ThumbnailUtils; //导入依赖的package包/类
@Test
public void testLocalVideoMicroThumbnailReturnsNull() throws Exception {
when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
when(
android.media.ThumbnailUtils.createVideoThumbnail(
mFile.getPath(), MediaStore.Images.Thumbnails.MICRO_KIND))
.thenReturn(null);
mLocalVideoThumbnailProducer.produceResults(mConsumer, mProducerContext);
mExecutor.runUntilIdle();
verify(mConsumer).onNewResult(null, Consumer.IS_LAST);
verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
Map<String, String> thumbnailNotFoundMap =
ImmutableMap.of(LocalVideoThumbnailProducer.CREATED_THUMBNAIL, "false");
verify(mProducerListener).onProducerFinishWithSuccess(
mRequestId, PRODUCER_NAME, thumbnailNotFoundMap);
verify(mProducerListener).onUltimateProducerReached(mRequestId, PRODUCER_NAME, false);
}
示例5: 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);
}
}
示例6: getMixImagesBitmap
import android.media.ThumbnailUtils; //导入依赖的package包/类
/**
* Constructing a bitmap that contains the given bitmaps(max is three).
*
* For given two bitmaps the result will be a half and half bitmap.
*
* For given three the result will be a half of the first bitmap and the second
* half will be shared equally by the two others.
*
* @param bitmaps Array of bitmaps to use for the final image.
* @param width width of the final image, A positive number.
* @param height height of the final image, A positive number.
*
* @return A Bitmap containing the given images.
* */
@Nullable public static Bitmap getMixImagesBitmap(@Size(min = 1) int width,@Size(min = 1) int height, @NonNull Bitmap...bitmaps){
if (height == 0 || width == 0) return null;
if (bitmaps.length == 0) return null;
Bitmap finalImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(finalImage);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
if (bitmaps.length == 2){
canvas.drawBitmap(ThumbnailUtils.extractThumbnail(bitmaps[0], width/2, height), 0, 0, paint);
canvas.drawBitmap(ThumbnailUtils.extractThumbnail(bitmaps[1], width/2, height), width/2, 0, paint);
}
else{
canvas.drawBitmap(ThumbnailUtils.extractThumbnail(bitmaps[0], width/2, height), 0, 0, paint);
canvas.drawBitmap(ThumbnailUtils.extractThumbnail(bitmaps[1], width/2, height/2), width/2, 0, paint);
canvas.drawBitmap(ThumbnailUtils.extractThumbnail(bitmaps[2], width/2, height/2), width/2, height/2, paint);
}
return finalImage;
}
示例7: 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;
}
示例8: getThumbFromDb
import android.media.ThumbnailUtils; //导入依赖的package包/类
/**
* 从系统媒体库获取图片,视频,音乐,apk文件的缩略图
*
* @param context Context
* @param mimeType 文件类型
* @param path 文件路径
* @param isList 是否为列表模式
* @return 缩略图
*/
public static Bitmap getThumbFromDb(Context context, String mimeType, String path, boolean isList) {
int width = isList ? 40 : 104;
int height = isList ? 40 : 72;
int thumbnailsValues = MediaStore.Images.Thumbnails.MINI_KIND;
if (mimeType.startsWith("image")) {
return ThumbnailUtils.extractThumbnail(getThumbImage(context, path, thumbnailsValues), FeViewUtils.dpToPx(width), FeViewUtils.dpToPx(height));
} else if (mimeType.startsWith("video")) {
return ThumbnailUtils.extractThumbnail(getVideoImage(context, path, thumbnailsValues), FeViewUtils.dpToPx(width), FeViewUtils.dpToPx(height));
} else if (mimeType.startsWith("audio") || mimeType.equals("application/ogg")) {
return ThumbnailUtils.extractThumbnail(getMusicThumb(path), FeViewUtils.dpToPx(width), FeViewUtils.dpToPx(height));
} else if (mimeType.equals("application/vnd.android.package-archive")) {
//app 图标在平铺模式下 56dp 设计规定
width = isList ? 40 : 56;
height = isList ? 40 : 56;
Bitmap bitmap = getLocalApkIcon(context.getPackageManager(), path);
if (bitmap != null) {
return FeThumbUtils.scaleBitMap(bitmap, FeViewUtils.dpToPx(width), FeViewUtils.dpToPx(height));
}
return null;
}
return null;
}
示例9: 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;
}
示例10: getImageThumbnail
import android.media.ThumbnailUtils; //导入依赖的package包/类
/**
* 获取图片的缩略图
*
* @param imagePath 图片路径
* @param maxWidth 最大宽度
* @param maxHeight 最大高度
* @return 一个bitmap缩略图
*/
public static Bitmap getImageThumbnail(String imagePath, int maxWidth, int maxHeight) {
Bitmap bitmap;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// 获取这个图片的宽和高,注意此处的bitmap为null
bitmap = BitmapFactory.decodeFile(imagePath, options);
options.inJustDecodeBounds = false; // 设为 false
// 计算缩放比
int h = options.outHeight;
int w = options.outWidth;
int beWidth = w / maxWidth;
int beHeight = h / maxHeight;
int be = beWidth < beHeight ? beWidth : beHeight;
if (be <= 0) {
be = 1;
}
options.inSampleSize = be;
// 重新读入图片,读取缩放后的bitmap,注意这次要把options.inJustDecodeBounds 设为 false
bitmap = BitmapFactory.decodeFile(imagePath, options);
// 利用ThumbnailUtils来创建缩略图,这里要指定要缩放哪个Bitmap对象
bitmap = ThumbnailUtils.extractThumbnail(bitmap, maxWidth, maxHeight,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
示例11: fadeThumbnailIn
import android.media.ThumbnailUtils; //导入依赖的package包/类
private void fadeThumbnailIn(SnippetArticle snippet, Bitmap thumbnail) {
mImageCallback = null;
if (thumbnail == null) return; // Nothing to do, we keep the placeholder.
// We need to crop and scale the downloaded bitmap, as the ImageView we set it on won't be
// able to do so when using a TransitionDrawable (as opposed to the straight bitmap).
// That's a limitation of TransitionDrawable, which doesn't handle layers of varying sizes.
Resources res = mThumbnailView.getResources();
int targetSize = res.getDimensionPixelSize(R.dimen.snippets_thumbnail_size);
Bitmap scaledThumbnail = ThumbnailUtils.extractThumbnail(
thumbnail, targetSize, targetSize, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
// Store the bitmap to skip the download task next time we display this snippet.
snippet.setThumbnailBitmap(scaledThumbnail);
// Cross-fade between the placeholder and the thumbnail.
Drawable[] layers = {mThumbnailView.getDrawable(),
new BitmapDrawable(mThumbnailView.getResources(), scaledThumbnail)};
TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
mThumbnailView.setImageDrawable(transitionDrawable);
transitionDrawable.startTransition(FADE_IN_ANIMATION_TIME_MS);
}
示例12: getScaledBitmap
import android.media.ThumbnailUtils; //导入依赖的package包/类
private Bitmap getScaledBitmap(Bitmap bitmap, int width, int height) {
double scale = icon.getScale();
if (scale <= 1)
return ThumbnailUtils.extractThumbnail(bitmap, (int) ((2 - scale) * width), (int) ((2 - scale) * height));
else if (bitmap.getWidth() > 1 && bitmap.getHeight() > 1) {
int widthMargin = (int) ((scale - 1) * width);
int heightMargin = (int) ((scale - 1) * height);
if (widthMargin > 0 && heightMargin > 0) {
Bitmap source = ThumbnailUtils.extractThumbnail(bitmap, (int) ((2 - scale) * width), (int) ((2 - scale) * height));
int dWidth = width + widthMargin;
int dHeight = height + heightMargin;
bitmap = Bitmap.createBitmap(dWidth, dHeight, bitmap.getConfig());
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(source, (dWidth - source.getWidth()) / 2, (dHeight - source.getHeight()) / 2, new Paint());
return bitmap;
}
} else if (bitmap.getWidth() > 0 && bitmap.getHeight() > 0)
return ThumbnailUtils.extractThumbnail(bitmap, width, height);
return null;
}
示例13: 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;
}
示例14: onInfo
import android.media.ThumbnailUtils; //导入依赖的package包/类
@Override
public void onInfo(MediaRecorder mediaRecorder, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED || what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED || what == MediaRecorder.MEDIA_RECORDER_INFO_UNKNOWN) {
MediaRecorder tempRecorder = recorder;
recorder = null;
if (tempRecorder != null) {
tempRecorder.stop();
tempRecorder.release();
}
if (onVideoTakeCallback != null) {
final Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(recordedFile, MediaStore.Video.Thumbnails.MINI_KIND);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (onVideoTakeCallback != null) {
onVideoTakeCallback.onFinishVideoRecording(bitmap);
onVideoTakeCallback = null;
}
}
});
}
}
}
示例15: onInfo
import android.media.ThumbnailUtils; //导入依赖的package包/类
@Override
public void onInfo(MediaRecorder mediaRecorder, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED || what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED || what == MediaRecorder.MEDIA_RECORDER_INFO_UNKNOWN) {
MediaRecorder tempRecorder = recorder;
recorder = null;
if (tempRecorder != null) {
tempRecorder.stop();
tempRecorder.release();
}
final Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(recordedFile, MediaStore.Video.Thumbnails.MINI_KIND);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
onVideoTakeCallback.onFinishVideoRecording(bitmap);
}
});
}
}