本文整理汇总了Java中android.graphics.Bitmap.Config类的典型用法代码示例。如果您正苦于以下问题:Java Config类的具体用法?Java Config怎么用?Java Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Config类属于android.graphics.Bitmap包,在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: roundBitmap
import android.graphics.Bitmap.Config; //导入依赖的package包/类
public static Bitmap roundBitmap(Bitmap bitmap, int i, int i2, float f, float f2, float f3,
float f4) throws Throwable {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Rect rect = new Rect(0, 0, width, height);
Bitmap createBitmap = (width == i && height == i2) ? Bitmap.createBitmap(bitmap.getWidth
(), bitmap.getHeight(), Config.ARGB_8888) : Bitmap.createBitmap(i, i2, Config
.ARGB_8888);
Canvas canvas = new Canvas(createBitmap);
Paint paint = new Paint();
Rect rect2 = new Rect(0, 0, i, i2);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(-12434878);
float[] fArr = new float[]{f, f, f2, f2, f3, f3, f4, f4};
ShapeDrawable shapeDrawable = new ShapeDrawable(new RoundRectShape(fArr, new RectF(0.0f,
0.0f, 0.0f, 0.0f), fArr));
shapeDrawable.setBounds(rect2);
shapeDrawable.draw(canvas);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect2, paint);
return createBitmap;
}
示例2: drawableToBitmap
import android.graphics.Bitmap.Config; //导入依赖的package包/类
public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
try {
Bitmap bitmap = Bitmap.createBitmap(Math.max(drawable.getIntrinsicWidth(), 2),
Math.max(drawable.getIntrinsicHeight(), 2), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (IllegalArgumentException e) {
e.printStackTrace();
return null;
}
}
示例3: combineImages
import android.graphics.Bitmap.Config; //导入依赖的package包/类
/**
* 合并Bitmap
*
* @param bgd 背景Bitmap
* @param fg 前景Bitmap
* @return 合成后的Bitmap
*/
public static Bitmap combineImages(Bitmap bgd, Bitmap fg) {
Bitmap bmp;
int width = bgd.getWidth() > fg.getWidth() ? bgd.getWidth() : fg
.getWidth();
int height = bgd.getHeight() > fg.getHeight() ? bgd.getHeight() : fg
.getHeight();
bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_ATOP));
Canvas canvas = new Canvas(bmp);
canvas.drawBitmap(bgd, 0, 0, null);
canvas.drawBitmap(fg, 0, 0, paint);
return bmp;
}
示例4: createQRCode
import android.graphics.Bitmap.Config; //导入依赖的package包/类
public static Bitmap createQRCode(String str, int size) throws WriterException {
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, size, size);
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for(int x = 0; x < width; x ++){
for(int y = 0; y < height; y ++){
if(matrix.get(x, y)){
pixels[y * width + x] = BLACK;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
示例5: MapClusterOptionsProvider
import android.graphics.Bitmap.Config; //导入依赖的package包/类
public MapClusterOptionsProvider(Resources resources) {
int poiSize = resources.getDimensionPixelSize(R.dimen.map_poi_size);
Drawable d = ResourcesCompat.getDrawable(resources, R.drawable.ic_wrapper_poi_cluster, null);
d.setBounds(0, 0, poiSize, poiSize);
Bitmap bitmap = Bitmap.createBitmap(poiSize, poiSize, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
d.draw(canvas);
baseBitmap = bitmap;
littleFontPaint.setColor(Color.BLACK);
littleFontPaint.setTextAlign(Align.CENTER);
littleFontPaint.setFakeBoldText(true);
littleFontPaint.setTextSize(resources.getDimension(R.dimen.map_marker_cluster_text_size_small));
bigFontPaint.setColor(Color.BLACK);
bigFontPaint.setTextAlign(Align.CENTER);
bigFontPaint.setFakeBoldText(true);
bigFontPaint.setTextSize(resources.getDimension(R.dimen.map_marker_cluster_text_size_big));
}
示例6: getRoundedCornerBitmap
import android.graphics.Bitmap.Config; //导入依赖的package包/类
/**
*圆角图片
* @param bitmap
* @return
*/
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = 12;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例7: initCanvas
import android.graphics.Bitmap.Config; //导入依赖的package包/类
private void initCanvas() {
mOriginalBitmapWidth = mOriginalBitmap.getWidth();
mOriginalBitmapHeight = mOriginalBitmap.getHeight();
// 初始状态值
mWaveOriginalY = mOriginalBitmapHeight;
mWaveY = 1.2f * mWaveOriginalY;
mBezierControlOriginalY = 1.25f * mWaveOriginalY;
mBezierControlY = mBezierControlOriginalY;
mXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
mBezierPath = new Path();
mCanvas = new Canvas();
mUltimateBitmap = Bitmap.createBitmap(mOriginalBitmapWidth, mOriginalBitmapHeight, Config.ARGB_8888);
mCanvas.setBitmap(mUltimateBitmap);
}
示例8: makeImageRequest
import android.graphics.Bitmap.Config; //导入依赖的package包/类
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight,
ScaleType scaleType, final String cacheKey) {
return new ImageRequest(requestUrl, new Listener<Bitmap>() {
@Override
public void onResponse(Bitmap response) {
onGetImageSuccess(cacheKey, response);
}
}, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
onGetImageError(cacheKey, error);
}
});
}
示例9: drawableToBitmap
import android.graphics.Bitmap.Config; //导入依赖的package包/类
public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable == null) return null;
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
int width = drawable.getIntrinsicWidth();
width = width > 0 ? width : 1;
int height = drawable.getIntrinsicHeight();
height = height > 0 ? height : 1;
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
示例10: createColorWheelBitmap
import android.graphics.Bitmap.Config; //导入依赖的package包/类
private Bitmap createColorWheelBitmap(int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
int colorCount = 12;
int colorAngleStep = 360 / 12;
int colors[] = new int[colorCount + 1];
float hsv[] = new float[] { 0f, 1f, 1f };
for (int i = 0; i < colors.length; i++) {
hsv[0] = (i * colorAngleStep + 180) % 360;
colors[i] = Color.HSVToColor(hsv);
}
colors[colorCount] = colors[0];
SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);
colorWheelPaint.setShader(composeShader);
Canvas canvas = new Canvas(bitmap);
canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);
return bitmap;
}
示例11: load_withColorDrawable_fixedSize_functionalBitmapTransform_doesNotRecycleOutput
import android.graphics.Bitmap.Config; //导入依赖的package包/类
@Test
public void load_withColorDrawable_fixedSize_functionalBitmapTransform_doesNotRecycleOutput()
throws ExecutionException, InterruptedException {
Drawable colorDrawable = new ColorDrawable(Color.RED);
int width = 100;
int height = 200;
Drawable result = GlideApp.with(context)
.load(colorDrawable)
.circleCrop()
.override(width, height)
.submit()
.get();
BitmapSubject.assertThat(result).isNotRecycled();
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
// Make sure we didn't put the same Bitmap twice.
Bitmap first = bitmapPool.get(width, height, Config.ARGB_8888);
Bitmap second = bitmapPool.get(width, height, Config.ARGB_8888);
assertThat(first).isNotSameAs(second);
}
示例12: ensureExpandedTexture
import android.graphics.Bitmap.Config; //导入依赖的package包/类
private void ensureExpandedTexture() {
if (this.mExpandedTitleTexture == null && !this.mExpandedBounds.isEmpty() && !TextUtils.isEmpty(this.mTextToDraw)) {
calculateOffsets(0.0f);
this.mTextureAscent = this.mTextPaint.ascent();
this.mTextureDescent = this.mTextPaint.descent();
int w = Math.round(this.mTextPaint.measureText(this.mTextToDraw, 0, this.mTextToDraw.length()));
int h = Math.round(this.mTextureDescent - this.mTextureAscent);
if (w > 0 && h > 0) {
this.mExpandedTitleTexture = Bitmap.createBitmap(w, h, Config.ARGB_8888);
new Canvas(this.mExpandedTitleTexture).drawText(this.mTextToDraw, 0, this.mTextToDraw.length(), 0.0f, ((float) h) - this.mTextPaint.descent(), this.mTextPaint);
if (this.mTexturePaint == null) {
this.mTexturePaint = new Paint(3);
}
}
}
}
示例13: toRoundCorner
import android.graphics.Bitmap.Config; //导入依赖的package包/类
/**
* 将图片变为圆角
* @param bitmap 原Bitmap图片
* @param pixels 图片圆角的弧度(单位:像素(px))
* @return 带有圆角的图片(Bitmap 类型)
*/
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例14: countBitmaps
import android.graphics.Bitmap.Config; //导入依赖的package包/类
@Override
public int countBitmaps(int width, int height, Config config) {
int c = 0;
synchronized (mCache) {
Iterator<Bitmap> it = mCache.iterator();
while (it.hasNext()) {
Bitmap bmp = it.next();
if (bmp.isRecycled()) {
it.remove();
continue;
}
if (bmp.getWidth() == width && bmp.getHeight() == height && bmp.getConfig() == config) {
c++;
}
}
}
return c;
}
示例15: recreateIcon
import android.graphics.Bitmap.Config; //导入依赖的package包/类
public synchronized Bitmap recreateIcon(Bitmap icon) {
int[] offset = new int[2];
Bitmap shadow = icon.extractAlpha(mBlurPaint, offset);
Bitmap result = Bitmap.createBitmap(mIconSize, mIconSize, Config.ARGB_8888);
mCanvas.setBitmap(result);
// Draw ambient shadow
mDrawPaint.setAlpha(AMBIENT_SHADOW_ALPHA);
mCanvas.drawBitmap(shadow, offset[0], offset[1], mDrawPaint);
// Draw key shadow
mDrawPaint.setAlpha(KEY_SHADOW_ALPHA);
mCanvas.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint);
// Draw the icon
mDrawPaint.setAlpha(255);
mCanvas.drawBitmap(icon, 0, 0, mDrawPaint);
mCanvas.setBitmap(null);
return result;
}