当前位置: 首页>>代码示例>>Java>>正文


Java Bitmap.createBitmap方法代码示例

本文整理汇总了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;
}
 
开发者ID:AndroidHensen,项目名称:FastBanner,代码行数:18,代码来源:IndicationView.java

示例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;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:27,代码来源:QRCodeEncoder.java

示例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;
    }
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:27,代码来源:CircleImageView.java

示例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;
}
 
开发者ID:fikyair,项目名称:musicplayer,代码行数:27,代码来源:BlurBitmap.java

示例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();
}
 
开发者ID:WGPlaner,项目名称:wg_planer,代码行数:27,代码来源:CircularImageView.java

示例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;
    }
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:17,代码来源:DrawableUtils.java

示例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);
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:13,代码来源:Utils.java

示例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;
    }
 
开发者ID:dmallcott,项目名称:DismissibleImageView,代码行数:28,代码来源:BlurTransformation.java

示例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;
}
 
开发者ID:penghuanliang,项目名称:Rxjava2.0Demo,代码行数:10,代码来源:DoActivity.java

示例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;
    }
}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:14,代码来源:IActivityManagerHookHandle.java

示例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;
}
 
开发者ID:viseator,项目名称:MontageCam,代码行数:30,代码来源:PhotoProcessing.java

示例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;
    }
 
开发者ID:malah-code,项目名称:Open-Quran-Radio,代码行数:11,代码来源:ImageHelper.java

示例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);
    }

}
 
开发者ID:n1rocket,项目名称:eggs-android,代码行数:41,代码来源:RoundedImageView.java

示例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);
}
 
开发者ID:asif-patel,项目名称:ImageEraser,代码行数:28,代码来源:MainActivity.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:TransformationUtilsTest.java


注:本文中的android.graphics.Bitmap.createBitmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。