Search in sources :

Example 21 with Canvas

use of android.graphics.Canvas in project Lazy by l123456789jy.

the class ImageProcessor method lum.

/**
     * 亮度处理
     * @param lumValue 新的亮度值
     * @return 改变了亮度值之后的图片
     */
public Bitmap lum(int lumValue) {
    //计算出符合要求的亮度值
    float newlumValue = lumValue * 1.0F / 127;
    //创建一个颜色矩阵
    ColorMatrix lumColorMatrix = new ColorMatrix();
    //设置亮度值
    lumColorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
    //创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(lumColorMatrix));
    //创建一个新的图片并创建画布
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    //将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint)

Example 22 with Canvas

use of android.graphics.Canvas in project Lazy by l123456789jy.

the class BitmapUtil method hue.

/**
     * 色相处理
     *
     * @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;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint)

Example 23 with Canvas

use of android.graphics.Canvas in project enroscar by stanfy.

the class BufferBitmapDecorator method reset.

/**
   * Prepare for new width and hight.
   * @param width new width
   * @param height new height
   */
protected void reset(final int width, final int height) {
    Bitmap bitmap = this.bitmap;
    // recycle old buffer
    if (bitmap != null) {
        bitmap.recycle();
    }
    // high quality
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    this.bitmap = bitmap;
    this.bitmapCanvas = new Canvas(bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas)

Example 24 with Canvas

use of android.graphics.Canvas in project enroscar by stanfy.

the class CropStartDecorator method setup.

@Override
public void setup(final int width, final int height, final int[] state, final int level, final int sourceWidth, final int sourceHeight) {
    // high quality
    this.bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    this.bitmapCanvas = new Canvas(bitmap);
    this.dstBounds.set(0, 0, Math.min(width, sourceWidth), Math.min(height, sourceHeight));
}
Also used : Canvas(android.graphics.Canvas)

Example 25 with Canvas

use of android.graphics.Canvas in project enroscar by stanfy.

the class MaskImageDecorator method processBitmap.

@Override
public Bitmap processBitmap(final Bitmap source, final Canvas sourceCanvas) {
    if (source == null) {
        return null;
    }
    final Bitmap buffer = this.bitmap;
    if (buffer == null) {
        return source;
    }
    buffer.eraseColor(0);
    final Canvas bufferCanvas = this.bitmapCanvas;
    final RectF rect = this.rect;
    // prepare mask
    switch(mode) {
        case CUSTOM_MASK:
            bufferCanvas.drawBitmap(mask, 0, 0, fillPaint);
            break;
        case CORNERS_MASK:
            if (radiusArray == null) {
                float radius = this.radius;
                final float r = Math.min(rect.width(), rect.height()) * 0.5f;
                if (radius > r) {
                    radius = r;
                }
                bufferCanvas.drawRoundRect(rect, radius, radius, fillPaint);
            } else {
                final Path path = this.path;
                path.reset();
                path.addRoundRect(rect, radiusArray, Path.Direction.CW);
                bufferCanvas.drawPath(path, fillPaint);
            }
            break;
        default:
            return source;
    }
    // main drawing
    bufferCanvas.drawBitmap(source, 0, 0, maskPaint);
    // modify source
    source.eraseColor(0);
    sourceCanvas.drawBitmap(buffer, 0, 0, null);
    // return source
    return source;
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas)

Aggregations

Canvas (android.graphics.Canvas)1237 Bitmap (android.graphics.Bitmap)890 Paint (android.graphics.Paint)609 Rect (android.graphics.Rect)257 BitmapDrawable (android.graphics.drawable.BitmapDrawable)192 RectF (android.graphics.RectF)136 PorterDuffXfermode (android.graphics.PorterDuffXfermode)103 Matrix (android.graphics.Matrix)80 Point (android.graphics.Point)76 Drawable (android.graphics.drawable.Drawable)68 BitmapShader (android.graphics.BitmapShader)60 Test (org.junit.Test)46 IOException (java.io.IOException)43 FileOutputStream (java.io.FileOutputStream)40 View (android.view.View)39 Path (android.graphics.Path)38 File (java.io.File)37 SuppressLint (android.annotation.SuppressLint)36 ColorMatrix (android.graphics.ColorMatrix)36 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)33