Search in sources :

Example 36 with Paint

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

the class ImageProcessor method saturation.

/**
     * 饱和度处理
     * @param saturationValue 新的饱和度值
     * @return 改变了饱和度值之后的图片
     */
public Bitmap saturation(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(), 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 37 with Paint

use of android.graphics.Paint 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 38 with Paint

use of android.graphics.Paint 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 39 with Paint

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

the class ShadowDecorator method processBitmap.

@Override
protected Bitmap processBitmap(final Bitmap source, final Canvas sourceCanvas) {
    final Bitmap buffer = this.bitmap;
    final Canvas bufferCanvas = this.bitmapCanvas;
    final Paint shadowPaint = this.shadowPaint;
    buffer.eraseColor(0);
    final float size = this.size;
    shadowPaint.setShadowLayer(blur, size, size, Color.BLACK);
    bufferCanvas.drawRect(dst, shadowPaint);
    bufferCanvas.drawBitmap(source, src, dst, null);
    source.eraseColor(0);
    sourceCanvas.drawBitmap(buffer, 0, 0, null);
    return source;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 40 with Paint

use of android.graphics.Paint in project WaveLoadingView by tangqi92.

the class WaveLoadingView method updateWaveShader.

private void updateWaveShader() {
    // http://stackoverflow.com/questions/17605662/illegalargumentexception-width-and-height-must-be-0-while-loading-bitmap-from
    if (bitmapBuffer == null || haveBoundsChanged()) {
        if (bitmapBuffer != null)
            bitmapBuffer.recycle();
        int width = getMeasuredWidth();
        int height = getMeasuredHeight();
        if (width > 0 && height > 0) {
            double defaultAngularFrequency = 2.0f * Math.PI / DEFAULT_WAVE_LENGTH_RATIO / width;
            float defaultAmplitude = height * DEFAULT_AMPLITUDE_RATIO;
            mDefaultWaterLevel = height * DEFAULT_WATER_LEVEL_RATIO;
            float defaultWaveLength = width;
            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            Paint wavePaint = new Paint();
            wavePaint.setStrokeWidth(2);
            wavePaint.setAntiAlias(true);
            // Draw default waves into the bitmap.
            // y=Asin(ωx+φ)+h
            final int endX = width + 1;
            final int endY = height + 1;
            float[] waveY = new float[endX];
            wavePaint.setColor(adjustAlpha(mWaveColor, 0.3f));
            for (int beginX = 0; beginX < endX; beginX++) {
                double wx = beginX * defaultAngularFrequency;
                float beginY = (float) (mDefaultWaterLevel + defaultAmplitude * Math.sin(wx));
                canvas.drawLine(beginX, beginY, beginX, endY, wavePaint);
                waveY[beginX] = beginY;
            }
            wavePaint.setColor(mWaveColor);
            final int wave2Shift = (int) (defaultWaveLength / 4);
            for (int beginX = 0; beginX < endX; beginX++) {
                canvas.drawLine(beginX, waveY[(beginX + wave2Shift) % endX], beginX, endY, wavePaint);
            }
            // Use the bitamp to create the shader.
            mWaveShader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
            this.mWavePaint.setShader(mWaveShader);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader) Point(android.graphics.Point) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)2248 Canvas (android.graphics.Canvas)466 Bitmap (android.graphics.Bitmap)415 Rect (android.graphics.Rect)267 RectF (android.graphics.RectF)231 TextPaint (android.text.TextPaint)178 PorterDuffXfermode (android.graphics.PorterDuffXfermode)124 Path (android.graphics.Path)120 Matrix (android.graphics.Matrix)105 TypedArray (android.content.res.TypedArray)81 BitmapDrawable (android.graphics.drawable.BitmapDrawable)75 Drawable (android.graphics.drawable.Drawable)65 BitmapShader (android.graphics.BitmapShader)63 Point (android.graphics.Point)60 SuppressLint (android.annotation.SuppressLint)57 View (android.view.View)54 Resources (android.content.res.Resources)42 Test (org.junit.Test)40 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)39 Typeface (android.graphics.Typeface)39