本文整理汇总了Java中android.graphics.Bitmap.createBitmap方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.createBitmap方法的具体用法?Java Bitmap.createBitmap怎么用?Java Bitmap.createBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.createBitmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawCircleBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap drawCircleBitmap(Bitmap bitmap) {
Bitmap circleBitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(circleBitmap);
Paint paint = new Paint();
paint.setDither(true);
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, getMeasuredWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, 0, 0, paint);
bitmap.recycle();
return circleBitmap;
}
示例2: encodeAsBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap encodeAsBitmap() throws WriterException {
if (!encoded) return null;
Map<EncodeHintType, Object> hints = null;
String encoding = guessAppropriateEncoding(contents);
if (encoding != null) {
hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, encoding);
}
MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix result = writer.encode(contents, format, dimension, dimension, hints);
int width = result.getWidth();
int height = result.getHeight();
int[] pixels = new int[width * height];
// All are 0, or black, by default
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
示例3: getBitmapFromDrawable
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap getBitmapFromDrawable(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
try {
Bitmap bitmap;
if (drawable instanceof ColorDrawable) {
bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (OutOfMemoryError e) {
return null;
}
}
示例4: blur
import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap blur(Bitmap bitmap, int w,int h) {
float scaleFactor = 1;
/**
* 这里是双重模糊手段
* scaleFactor是将bitmap缩小至原来的 n 倍u,然后在填充的时候被拉伸 n 倍,从而模糊
* radius是模糊半径,有FastBlur处理
* 两者都是乘积越大,越模糊
* */
float radius = 20;
if (bitmap != null) {
scaleFactor = 18;
radius = 8;
}
Log.e("test","w = " +w+ " h = "+ h / scaleFactor + "bitmap = "+bitmap);
Bitmap overlay = Bitmap.createBitmap((int) (bitmap.getWidth() / scaleFactor),
(int) (bitmap.getHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.scale(1 / scaleFactor, 1 / scaleFactor);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(bitmap, 0, 0, paint);
overlay = FastBlur.doBlur(overlay, (int) radius, true);
return overlay;
}
示例5: initializeBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
private void initializeBitmap() {
Drawable drawable = getDrawable();
if (drawable == null) {
return;
} else if (drawable instanceof BitmapDrawable) {
mBitmap = ((BitmapDrawable) drawable).getBitmap();
setup();
return;
} else if (drawable instanceof ColorDrawable) {
mBitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
} else {
mBitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
BITMAP_CONFIG);
}
Canvas canvas = new Canvas(mBitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
setup();
}
示例6: drawableToBitMap
import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap drawableToBitMap(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
return bitmapDrawable.getBitmap();
} else {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
}
示例7: drawableToIcon
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Demonstrates converting any Drawable to an Icon, for use as a marker icon.
*/
public static Icon drawableToIcon(@NonNull Context context, @DrawableRes int id) {
Drawable vectorDrawable = ResourcesCompat.getDrawable(context.getResources(), id, context.getTheme());
Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
vectorDrawable.draw(canvas);
return IconFactory.getInstance(context).fromBitmap(bitmap);
}
示例8: transform
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override public Bitmap transform(Bitmap source) {
int scaledWidth = source.getWidth() / mSampling;
int scaledHeight = source.getHeight() / mSampling;
Bitmap bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(source, 0, 0, paint);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try {
bitmap = RsBlur.blur(mContext, bitmap, mRadius);
} catch (RSRuntimeException e) {
bitmap = FastBlur.blur(bitmap, mRadius, true);
}
} else {
bitmap = FastBlur.blur(bitmap, mRadius, true);
}
//source.recycle();
return bitmap;
}
示例9: drawTBit
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap drawTBit(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
示例10: drawableToBitMap
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap drawableToBitMap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
return bitmapDrawable.getBitmap();
} else {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
}
示例11: rotate
import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap rotate(Bitmap bitmap, int angle) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Config config = bitmap.getConfig();
nativeInitBitmap(width, height);
sendBitmapToNative(bitmap);
if (angle == 90) {
nativeRotate90();
bitmap.recycle();
bitmap = Bitmap.createBitmap(height, width, config);
bitmap = getBitmapFromNative(bitmap);
nativeDeleteBitmap();
} else if (angle == 180) {
nativeRotate180();
bitmap.recycle();
bitmap = Bitmap.createBitmap(width, height, config);
bitmap = getBitmapFromNative(bitmap);
nativeDeleteBitmap();
} else if (angle == 270) {
nativeRotate180();
nativeRotate90();
bitmap.recycle();
bitmap = Bitmap.createBitmap(height, width, config);
bitmap = getBitmapFromNative(bitmap);
nativeDeleteBitmap();
}
return bitmap;
}
示例12: composeImages
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap composeImages(Bitmap background, int size) {
// compose output image
Bitmap outputImage = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(outputImage);
canvas.drawBitmap(background, 0, 0, null);
canvas.drawBitmap(mInputImage, createTransformationMatrix(size), null);
return outputImage;
}
示例13: onDraw
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
try {
Drawable drawable = getDrawable();
if (drawable == null) {
return;
}
if (getWidth() == 0 || getHeight() == 0) {
return;
}
Bitmap bitmap;
int w = getWidth(), h = getHeight();
if (w <= 0 || h <= 0) {
return;
}
if (drawable instanceof BitmapDrawable) {
Bitmap b = ((BitmapDrawable) drawable).getBitmap();
bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
} else if (drawable instanceof ColorDrawable) {
bitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
c.drawColor(((ColorDrawable) drawable).getColor());
} else {
return;
}
Bitmap roundBitmap = getRoundedCroppedBitmap(bitmap, Math.min(w, h));
canvas.drawBitmap(roundBitmap, 0, 0, null);
} catch (Exception e) {
Log.e(TAG, "onDraw Exception", e);
}
}
示例14: makeHighResolutionOutput
import android.graphics.Bitmap; //导入方法依赖的package包/类
private void makeHighResolutionOutput() {
if (this.isImageResized) {
Bitmap solidColor = Bitmap.createBitmap(this.originalBitmap.getWidth(), this.originalBitmap.getHeight(), this.originalBitmap.getConfig());
Canvas canvas = new Canvas(solidColor);
Paint paint = new Paint();
paint.setColor(Color.argb(255, 255, 255, 255));
Rect src = new Rect(0, 0, this.bitmapMaster.getWidth(), this.bitmapMaster.getHeight());
Rect dest = new Rect(0, 0, this.originalBitmap.getWidth(), this.originalBitmap.getHeight());
canvas.drawRect(dest, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_OUT));
canvas.drawBitmap(this.bitmapMaster, src, dest, paint);
this.highResolutionOutput = null;
this.highResolutionOutput = Bitmap.createBitmap(this.originalBitmap.getWidth(), this.originalBitmap.getHeight(), this.originalBitmap.getConfig());
Canvas canvas1 = new Canvas(this.highResolutionOutput);
canvas1.drawBitmap(this.originalBitmap, 0.0f, 0.0f, null);
Paint paint1 = new Paint();
paint1.setXfermode(new PorterDuffXfermode(Mode.DST_OUT));
canvas1.drawBitmap(solidColor, 0.0f, 0.0f, paint1);
if (solidColor != null && !solidColor.isRecycled()) {
solidColor.recycle();
solidColor = null;
}
return;
}
this.highResolutionOutput = null;
this.highResolutionOutput = this.bitmapMaster.copy(this.bitmapMaster.getConfig(), true);
}
示例15: testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Test
public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform,
toTransform.getWidth() / 2, toTransform.getHeight() / 2);
assertTrue(result.hasAlpha());
}