本文整理匯總了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);
}
});
}
}