java类android.graphics.Bitmap.Config的实例源码

BitmapHelper.java 文件源码 项目:boohee_v5.6 阅读 46 收藏 0 点赞 0 评论 0
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;
}
SelectableRoundedImageView.java 文件源码 项目:boohee_v5.6 阅读 47 收藏 0 点赞 0 评论 0
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;
    }
}
XBitmapUtils.java 文件源码 项目:XFrame 阅读 42 收藏 0 点赞 0 评论 0
/**
 * 合并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;
}
EncodingHandler.java 文件源码 项目:tvConnect_android 阅读 55 收藏 0 点赞 0 评论 0
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;
}
MapClusterOptionsProvider.java 文件源码 项目:referendum_1o_android 阅读 38 收藏 0 点赞 0 评论 0
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));
}
ImageTools.java 文件源码 项目:FreeStreams-TVLauncher 阅读 54 收藏 0 点赞 0 评论 0
/**
 *圆角图片
 * @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;

}
BGAMoocStyleRefreshView.java 文件源码 项目:GitHub 阅读 35 收藏 0 点赞 0 评论 0
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);
}
ImageLoader.java 文件源码 项目:GitHub 阅读 45 收藏 0 点赞 0 评论 0
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);
        }
    });
}
Utils.java 文件源码 项目:GravityBox 阅读 46 收藏 0 点赞 0 评论 0
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;
}
ColorPicker.java 文件源码 项目:buildAPKsApps 阅读 39 收藏 0 点赞 0 评论 0
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;

    }
DrawableTransformationTest.java 文件源码 项目:GitHub 阅读 42 收藏 0 点赞 0 评论 0
@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);
}
CollapsingTextHelper.java 文件源码 项目:boohee_v5.6 阅读 40 收藏 0 点赞 0 评论 0
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);
            }
        }
    }
}
FileUtil.java 文件源码 项目:TakePhoto 阅读 54 收藏 0 点赞 0 评论 0
/**
 * 将图片变为圆角
 * @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;
}
BitmapPoolFactory.java 文件源码 项目:homunculus 阅读 46 收藏 0 点赞 0 评论 0
@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;
}
ShadowGenerator.java 文件源码 项目:LaunchEnr 阅读 37 收藏 0 点赞 0 评论 0
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;
}
XBitmapUtils.java 文件源码 项目:XFrame 阅读 52 收藏 0 点赞 0 评论 0
/**
 * 色相处理
 *
 * @param bitmap   原图
 * @param hueValue 新的色相值
 * @return 改变了色相值之后的图片
 */
public static Bitmap hue(Bitmap bitmap, int hueValue) {
    // 计算出符合要求的色相值
    float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;
    // 创建一个颜色矩阵
    ColorMatrix hueColorMatrix = new ColorMatrix();
    // 控制让红色区在色轮上旋转的角度
    hueColorMatrix.setRotate(0, newHueValue);
    // 控制让绿红色区在色轮上旋转的角度
    hueColorMatrix.setRotate(1, newHueValue);
    // 控制让蓝色区在色轮上旋转的角度
    hueColorMatrix.setRotate(2, newHueValue);
    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(hueColorMatrix));
    // 创建一个新的图片并创建画布
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
GameView.java 文件源码 项目:buildAPKsSamples 阅读 44 收藏 0 点赞 0 评论 0
private Bitmap getResBitmap(int bmpResId) {
    Options opts = new Options();
    opts.inDither = false;

    Resources res = getResources();
    Bitmap bmp = BitmapFactory.decodeResource(res, bmpResId, opts);

    if (bmp == null && isInEditMode()) {
        // BitmapFactory.decodeResource doesn't work from the rendering
        // library in Eclipse's Graphical Layout Editor. Use this workaround instead.

        Drawable d = res.getDrawable(bmpResId);
        int w = d.getIntrinsicWidth();
        int h = d.getIntrinsicHeight();
        bmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
        Canvas c = new Canvas(bmp);
        d.setBounds(0, 0, w - 1, h - 1);
        d.draw(c);
    }

    return bmp;
}
SharedElementCallback.java 文件源码 项目:letv 阅读 46 收藏 0 点赞 0 评论 0
private static Bitmap createDrawableBitmap(Drawable drawable) {
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    if (width <= 0 || height <= 0) {
        return null;
    }
    float scale = Math.min(1.0f, ((float) MAX_IMAGE_SIZE) / ((float) (width * height)));
    if ((drawable instanceof BitmapDrawable) && scale == 1.0f) {
        return ((BitmapDrawable) drawable).getBitmap();
    }
    int bitmapWidth = (int) (((float) width) * scale);
    int bitmapHeight = (int) (((float) height) * scale);
    Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Rect existingBounds = drawable.getBounds();
    int left = existingBounds.left;
    int top = existingBounds.top;
    int right = existingBounds.right;
    int bottom = existingBounds.bottom;
    drawable.setBounds(0, 0, bitmapWidth, bitmapHeight);
    drawable.draw(canvas);
    drawable.setBounds(left, top, right, bottom);
    return bitmap;
}
BlurUtils.java 文件源码 项目:letv 阅读 42 收藏 0 点赞 0 评论 0
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void blurAdvanced(Context context, Bitmap bkg, View view) {
    if (bkg != null) {
        Bitmap overlay = Bitmap.createBitmap(bkg.getWidth(), bkg.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(overlay);
        Paint paint = new Paint();
        paint.setFlags(2);
        canvas.drawBitmap(bkg, 0.0f, 0.0f, paint);
        overlay = FastBlur.doBlur(overlay, (int) 12.0f, true);
        if (LetvUtils.getSDKVersion() >= 16) {
            view.setBackground(new BitmapDrawable(context.getResources(), overlay));
        } else {
            view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
        }
    }
}
s.java 文件源码 项目:boohee_v5.6 阅读 50 收藏 0 点赞 0 评论 0
public static Bitmap a(Drawable drawable) {
    int i = 1;
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }
    int intrinsicWidth = drawable.getIntrinsicWidth();
    if (intrinsicWidth <= 0) {
        intrinsicWidth = 1;
    }
    int intrinsicHeight = drawable.getIntrinsicHeight();
    if (intrinsicHeight > 0) {
        i = intrinsicHeight;
    }
    Bitmap createBitmap = Bitmap.createBitmap(intrinsicWidth, i, Config.ARGB_8888);
    Canvas canvas = new Canvas(createBitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return createBitmap;
}
PhotoProcessing.java 文件源码 项目:MontageCam 阅读 46 收藏 0 点赞 0 评论 0
private static Bitmap getBitmapFromNative(Bitmap bitmap) {
    int width = nativeGetBitmapWidth();
    int height = nativeGetBitmapHeight();

    if (bitmap == null || width != bitmap.getWidth()
            || height != bitmap.getHeight() || !bitmap.isMutable()) { // in
        Config config = Config.ARGB_8888;
        if (bitmap != null) {
            config = bitmap.getConfig();
            bitmap.recycle();
        }
        bitmap = Bitmap.createBitmap(width, height, config);
    }

    int[] pixels = new int[width];
    for (int y = 0; y < height; y++) {
        nativeGetBitmapRow(y, pixels);
        bitmap.setPixels(pixels, 0, width, 0, y, width, 1);
    }

    return bitmap;
}
ImageUtils.java 文件源码 项目:gamesboard 阅读 47 收藏 0 点赞 0 评论 0
public static Bitmap createBitmap(InputStream in, int w, int h, boolean closeStream) {
        if (in == null) {
            return null;
        }
        com.larvalabs.svgandroid.SVG svg;
        svg = new SVGBuilder().readFromInputStream(in).build();

        Bitmap bitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        Picture pic = svg.getPicture();
//        svg.renderToCanvas(canvas/*, new RectF(0f, 0f, (float)w, (float)h)*/);
//        svg.renderToCanvas(canvas, new RectF(0f, 0f, (float)w, (float)h));
        canvas.drawPicture(pic, new Rect(0, 0, w, h));
        if (closeStream) {
            try {
                in.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return bitmap;
    }
XBitmapUtils.java 文件源码 项目:XFrame 阅读 39 收藏 0 点赞 0 评论 0
/**
 * 将彩色图转换为黑白图
 *
 * @param bmp 位图
 * @return 返回转换好的位图
 */
public static Bitmap convertToBlackWhite(Bitmap bmp) {
    int width = bmp.getWidth();
    int height = bmp.getHeight();
    int[] pixels = new int[width * height];
    bmp.getPixels(pixels, 0, width, 0, 0, width, height);

    int alpha = 0xFF << 24; // 默认将bitmap当成24色图片
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int grey = pixels[width * i + j];

            int red = ((grey & 0x00FF0000) >> 16);
            int green = ((grey & 0x0000FF00) >> 8);
            int blue = (grey & 0x000000FF);

            grey = (int) (red * 0.3 + green * 0.59 + blue * 0.11);
            grey = alpha | (grey << 16) | (grey << 8) | grey;
            pixels[width * i + j] = grey;
        }
    }
    Bitmap newBmp = Bitmap.createBitmap(width, height, Config.RGB_565);
    newBmp.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBmp;
}
RoundedBitmapDisplayer.java 文件源码 项目:android-project-gallery 阅读 38 收藏 0 点赞 0 评论 0
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int roundPixels, Rect srcRect, Rect destRect, int width,
                                             int height) {
    Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final RectF destRectF = new RectF(destRect);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(0xFF000000);
    canvas.drawRoundRect(destRectF, roundPixels, roundPixels, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, srcRect, destRectF, paint);

    return output;
}
XBitmapUtils.java 文件源码 项目:XFrame 阅读 45 收藏 0 点赞 0 评论 0
/**
 * 饱和度处理
 *
 * @param bitmap          原图
 * @param saturationValue 新的饱和度值
 * @return 改变了饱和度值之后的图片
 */
public static Bitmap saturation(Bitmap bitmap, int saturationValue) {
    // 计算出符合要求的饱和度值
    float newSaturationValue = saturationValue * 1.0F / 127;
    // 创建一个颜色矩阵
    ColorMatrix saturationColorMatrix = new ColorMatrix();
    // 设置饱和度值
    saturationColorMatrix.setSaturation(newSaturationValue);
    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(saturationColorMatrix));
    // 创建一个新的图片并创建画布
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
ButtonFloat.java 文件源码 项目:XERUNG 阅读 53 收藏 0 点赞 0 评论 0
public Bitmap cropCircle(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());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
            bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
SharedElementCallback.java 文件源码 项目:boohee_v5.6 阅读 43 收藏 0 点赞 0 评论 0
private static Bitmap createDrawableBitmap(Drawable drawable) {
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    if (width <= 0 || height <= 0) {
        return null;
    }
    float scale = Math.min(1.0f, ((float) MAX_IMAGE_SIZE) / ((float) (width * height)));
    if ((drawable instanceof BitmapDrawable) && scale == 1.0f) {
        return ((BitmapDrawable) drawable).getBitmap();
    }
    int bitmapWidth = (int) (((float) width) * scale);
    int bitmapHeight = (int) (((float) height) * scale);
    Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Rect existingBounds = drawable.getBounds();
    int left = existingBounds.left;
    int top = existingBounds.top;
    int right = existingBounds.right;
    int bottom = existingBounds.bottom;
    drawable.setBounds(0, 0, bitmapWidth, bitmapHeight);
    drawable.draw(canvas);
    drawable.setBounds(left, top, right, bottom);
    return bitmap;
}
LayoutRipple.java 文件源码 项目:XERUNG 阅读 45 收藏 0 点赞 0 评论 0
/**
 * @param bitmap
 * @return 设置涟漪的边界,涟漪在这个区域里面可见。这里可以设置四角的弧度数
 */
public Bitmap cropRoundRect(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());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
    canvas.drawRoundRect(rectF, rippleBorderRadius, rippleBorderRadius, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
ImageHelper.java 文件源码 项目:BBSSDK-for-Android 阅读 49 收藏 0 点赞 0 评论 0
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    if (bitmap == null) {
        return null;
    }
    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;
}
XBitmapUtils.java 文件源码 项目:XFrame 阅读 54 收藏 0 点赞 0 评论 0
/**
 * 从View获取Bitmap
 *
 * @param view View
 * @return Bitmap
 */
public static Bitmap getBitmapFromView(View view) {
    if (view == null) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
            Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    view.layout(view.getLeft(), view.getTop(), view.getRight(),
            view.getBottom());
    view.draw(canvas);

    return bitmap;
}


问题


面经


文章

微信
公众号

扫码关注公众号