本文整理了Java中android.graphics.Bitmap.createScaledBitmap()
方法的一些代码示例,展示了Bitmap.createScaledBitmap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.createScaledBitmap()
方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:createScaledBitmap
暂无
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* 将Bitmap转换成指定大小
*
* @param bitmap
* @param width
* @param height
* @return
*/
public static Bitmap createBitmapBySize(Bitmap bitmap, int width, int height) {
return Bitmap.createScaledBitmap(bitmap, width, height, true);
}
代码示例来源:origin: mttkay/ignition
public static Drawable scaleDrawable(Context context, int drawableResourceId, int width,
int height) {
Bitmap sourceBitmap = BitmapFactory.decodeResource(context.getResources(),
drawableResourceId);
return new BitmapDrawable(Bitmap.createScaledBitmap(sourceBitmap, width, height, true));
}
代码示例来源:origin: Zomato/AndroidPhotoFilters
@Override
public Bitmap process(Bitmap inputImage) {
Bitmap vignette = BitmapFactory.decodeResource(context.getResources(), R.drawable.vignette);
vignette = Bitmap.createScaledBitmap(vignette, inputImage.getWidth(), inputImage.getHeight(), true);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setAlpha(alpha);
Canvas comboImage = new Canvas(inputImage);
comboImage.drawBitmap(vignette, 0f, 0f, paint);
return inputImage;
}
代码示例来源:origin: googlemaps/android-maps-utils
/**
* Scales a Bitmap to a specified float.
*
* @param unscaledBitmap Unscaled bitmap image to scale.
* @param scale Scale value. A "1.0" scale value corresponds to the original size of the Bitmap
* @return A scaled bitmap image
*/
private static BitmapDescriptor scaleIcon(Bitmap unscaledBitmap, Double scale) {
int width = (int) (unscaledBitmap.getWidth() * scale);
int height = (int) (unscaledBitmap.getHeight() * scale);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(unscaledBitmap, width, height, false);
return BitmapDescriptorFactory.fromBitmap(scaledBitmap);
}
代码示例来源:origin: Aspsine/SwipeToLoadLayout
private void createBitmaps() {
mSky = BitmapFactory.decodeResource(getContext().getResources(), R.mipmap.yalantis_phoenix_sky);
mSky = Bitmap.createScaledBitmap(mSky, mScreenWidth, mSkyHeight, true);
mTown = BitmapFactory.decodeResource(getContext().getResources(), R.mipmap.yalantis_phoenix_buildings);
mTown = Bitmap.createScaledBitmap(mTown, mScreenWidth, (int) (mScreenWidth * TOWN_RATIO), true);
mSun = BitmapFactory.decodeResource(getContext().getResources(), R.mipmap.yalantis_phoenix_sun);
mSun = Bitmap.createScaledBitmap(mSun, mSunSize, mSunSize, true);
}
代码示例来源:origin: lyft/scissors
@Override
protected Bitmap transform(BitmapPool bitmapPool, Bitmap source, int outWidth, int outHeight) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
Rect target = CropViewExtensions.computeTargetSize(sourceWidth, sourceHeight, viewportWidth, viewportHeight);
int targetWidth = target.width();
int targetHeight = target.height();
return Bitmap.createScaledBitmap(
source,
targetWidth,
targetHeight,
true);
}
代码示例来源:origin: davemorrissey/subsampling-scale-image-view
private void initialise() {
float density = getResources().getDisplayMetrics().densityDpi;
pin = BitmapFactory.decodeResource(this.getResources(), drawable.pushpin_blue);
float w = (density/420f) * pin.getWidth();
float h = (density/420f) * pin.getHeight();
pin = Bitmap.createScaledBitmap(pin, (int)w, (int)h, true);
}
代码示例来源:origin: aporter/coursera-android
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mParentWidth = mFrame.getWidth();
mParentHeight = mFrame.getHeight();
int size = Math.round(Math.min(mParentHeight, mParentWidth) / 1.33f);
mBitmap = Bitmap.createScaledBitmap(mBitmap, size, size, false);
mBitmapWidth = mBitmap.getWidth();
mParentCenterX = mParentWidth / 2;
mParentCenterY = mParentHeight / 2;
mViewLeftY = mParentCenterX - mBitmapWidth / 2;
mViewTopX = mParentCenterY - mBitmapWidth / 2;
}
代码示例来源:origin: lyft/scissors
@Override
public Bitmap transform(Bitmap source) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
Rect target = CropViewExtensions.computeTargetSize(sourceWidth, sourceHeight, viewportWidth, viewportHeight);
final Bitmap result = Bitmap.createScaledBitmap(
source,
target.width(),
target.height(),
true);
if (result != source) {
source.recycle();
}
return result;
}
代码示例来源:origin: Zomato/AndroidPhotoFilters
@Override
public void onThumbnailClick(Filter filter) {
placeHolderImageView.setImageBitmap(filter.processFilter(Bitmap.createScaledBitmap(BitmapFactory.decodeResource(this.getApplicationContext().getResources(), R.drawable.photo), 640, 640, false)));
}
}
代码示例来源:origin: Zomato/AndroidPhotoFilters
public static List<ThumbnailItem> processThumbs(Context context) {
for (ThumbnailItem thumb : filterThumbs) {
// scaling down the image
float size = context.getResources().getDimension(R.dimen.thumbnail_size);
thumb.image = Bitmap.createScaledBitmap(thumb.image, (int) size, (int) size, false);
thumb.image = thumb.filter.processFilter(thumb.image);
//cropping circle
thumb.image = GeneralUtils.generateCircularBitmap(thumb.image);
processedThumbs.add(thumb);
}
return processedThumbs;
}
代码示例来源:origin: lyft/scissors
@Override
public void display(Bitmap source, ImageAware imageAware, LoadedFrom loadedFrom) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
Rect target = CropViewExtensions.computeTargetSize(sourceWidth, sourceHeight, viewportWidth, viewportHeight);
final Bitmap result = Bitmap.createScaledBitmap(
source,
target.width(),
target.height(),
true);
if (result != source) {
source.recycle();
}
imageAware.setImageBitmap(result);
}
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
private Bitmap parse(byte[] byteArray) throws OutOfMemoryError {
BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
Bitmap bitmap;
if (maxWidth == 0 && maxHeight == 0) {
decodeOptions.inPreferredConfig = decodeConfig;
bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, decodeOptions);
} else {
decodeOptions.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, decodeOptions);
int actualWidth = decodeOptions.outWidth;
int actualHeight = decodeOptions.outHeight;
int desiredWidth = getResizedDimension(maxWidth, maxHeight, actualWidth, actualHeight, scaleType);
int desiredHeight = getResizedDimension(maxHeight, maxWidth, actualHeight, actualWidth, scaleType);
decodeOptions.inJustDecodeBounds = false;
decodeOptions.inSampleSize = findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
Bitmap tempBitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, decodeOptions);
if (tempBitmap != null && (tempBitmap.getWidth() > desiredWidth || tempBitmap.getHeight() > desiredHeight)) {
bitmap = Bitmap.createScaledBitmap(tempBitmap, desiredWidth, desiredHeight, true);
tempBitmap.recycle();
} else {
bitmap = tempBitmap;
}
}
return bitmap;
}
代码示例来源:origin: bumptech/glide
private Bitmap decodeBitmap() {
Context context = InstrumentationRegistry.getTargetContext();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
int resourceId = ResourceIds.raw.canonical;
Bitmap result = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
if (scaleFactor != null) {
result = Bitmap.createScaledBitmap(
result,
(int) (result.getWidth() * scaleFactor),
(int) (result.getHeight() * scaleFactor),
/*filter=*/false);
}
// Make sure the Bitmap is immutable.
return result;
}
}
代码示例来源:origin: Zomato/AndroidPhotoFilters
private void initUIWidgets() {
thumbListView = (RecyclerView) findViewById(R.id.thumbnails);
placeHolderImageView = (ImageView) findViewById(R.id.place_holder_imageview);
placeHolderImageView.setImageBitmap(Bitmap.createScaledBitmap(BitmapFactory.decodeResource(this.getApplicationContext().getResources(), R.drawable.photo), 640, 640, false));
initHorizontalList();
}
代码示例来源:origin: Rajawali/Rajawali
private void loadGIF() {
Context context = TextureManager.getInstance().getContext();
mMovie = Movie.decodeStream(context.getResources().openRawResource(mResourceId));
mWidth = mMovie.width();
mHeight = mMovie.height();
mGIFBitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
mCanvas = new Canvas(mGIFBitmap);
mMovie.draw(mCanvas, 0, 0);
mBitmap = Bitmap.createScaledBitmap(mGIFBitmap, mTextureSize, mTextureSize, false);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void bitmapsAreReused() {
Bitmap b = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
Bitmap b1 = Bitmap.createBitmap(b, 0, 0, 10, 10);
assertThat(b1).isSameAs(b);
Bitmap b2 = Bitmap.createBitmap(b, 0, 0, 10, 10, null, false);
assertThat(b2).isSameAs(b);
Bitmap b3 = Bitmap.createScaledBitmap(b, 10, 10, false);
assertThat(b3).isSameAs(b);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldCreateScaledBitmap() throws Exception {
Bitmap originalBitmap = create("Original bitmap");
Bitmap scaledBitmap = Bitmap.createScaledBitmap(originalBitmap, 100, 200, false);
assertThat(shadowOf(scaledBitmap).getDescription())
.isEqualTo("Original bitmap scaled to 100 x 200");
assertThat(scaledBitmap.getWidth()).isEqualTo(100);
assertThat(scaledBitmap.getHeight()).isEqualTo(200);
scaledBitmap.getPixels(new int[20000], 0, 0, 0, 0, 100, 200);
}
代码示例来源:origin: facebook/facebook-android-sdk
private void setBlankProfilePicture() {
// If we have a pending image download request cancel it
if (lastRequest != null) {
ImageDownloader.cancelRequest(lastRequest);
}
if (customizedDefaultProfilePicture == null) {
int blankImageResource = isCropped() ?
R.drawable.com_facebook_profile_picture_blank_square :
R.drawable.com_facebook_profile_picture_blank_portrait;
setImageBitmap(BitmapFactory.decodeResource(getResources(), blankImageResource));
} else {
// Update profile image dimensions.
updateImageQueryParameters();
// Resize inputBitmap to new dimensions of queryWidth and queryHeight.
Bitmap scaledBitmap = Bitmap.createScaledBitmap(
customizedDefaultProfilePicture, queryWidth, queryHeight, false);
setImageBitmap(scaledBitmap);
}
}
代码示例来源:origin: Rajawali/Rajawali
public void update() throws TextureException
{
if(mMovie == null || mMovie.duration() == 0) return;
long now = SystemClock.uptimeMillis();
int relTime = (int)((now - mStartTime) % mMovie.duration());
mMovie.setTime(relTime);
mGIFBitmap.eraseColor(Color.TRANSPARENT);
mMovie.draw(mCanvas, 0, 0);
mBitmap = Bitmap.createScaledBitmap(mGIFBitmap, mTextureSize, mTextureSize, false);
TextureManager.getInstance().replaceTexture(this);
replace();
}
内容来源于网络,如有侵权,请联系作者删除!