Java Code Examples for android.graphics.Paint.setARGB()

The following are Jave code examples for showing how to use setARGB() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Android-Simple-MjpegViewer   File: MjpegViewThread.java   View Source Code Vote up 7 votes
public MjpegViewThread(SurfaceHolder surfaceHolder, View view){
    mSurfaceHolder = surfaceHolder;
    mRun = false;
    mCallback = null;
    dispWidth = view.getWidth();
    dispHeight = view.getHeight();
    prevdispWidth = dispWidth;
    prevdispHeight = dispHeight;
    destRect = new Rect(0,0,dispWidth,dispHeight);
    destSrc = null;
    displayMode = 1; // Default : SIZE_FIT_MODE
    prevdisplayMode = 1;

    bgColor = new Paint();
    bgColor.setStyle(Paint.Style.FILL);
    bgColor.setARGB(255, 0, 0, 0);
}
 
Example 2
Project: q-mail   File: ContactPictureLoader.java   View Source Code Vote up 6 votes
private Bitmap drawTextAndBgColorOnBitmap(Bitmap bitmap, FallbackGlideParams params) {
    Canvas canvas = new Canvas(bitmap);

    int rgb = calcUnknownContactColor(params.address);
    bitmap.eraseColor(rgb);

    String letter = calcUnknownContactLetter(params.address);

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Style.FILL);
    paint.setARGB(255, 255, 255, 255);
    paint.setTextSize(mPictureSizeInPx * 3 / 4); // just scale this down a bit
    Rect rect = new Rect();
    paint.getTextBounds(letter, 0, 1, rect);
    float width = paint.measureText(letter);
    canvas.drawText(letter,
            (mPictureSizeInPx / 2f) - (width / 2f),
            (mPictureSizeInPx / 2f) + (rect.height() / 2f), paint);

    return bitmap;
}
 
Example 3
Project: RNLearn_Project1   File: ARTShapeShadowNode.java   View Source Code Vote up 6 votes
/**
 * Sets up {@link #mPaint} according to the props set on a shadow view. Returns {@code true}
 * if the fill should be drawn, {@code false} if not.
 */
protected boolean setupFillPaint(Paint paint, float opacity) {
  if (mFillColor != null && mFillColor.length > 0) {
    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    int colorType = (int) mFillColor[0];
    switch (colorType) {
      case 0:
        paint.setARGB(
            (int) (mFillColor.length > 4 ? mFillColor[4] * opacity * 255 : opacity * 255),
            (int) (mFillColor[1] * 255),
            (int) (mFillColor[2] * 255),
            (int) (mFillColor[3] * 255));
        break;
      default:
        // TODO(6352048): Support gradients etc.
        FLog.w(ReactConstants.TAG, "ART: Color type " + colorType + " not supported!");
    }
    return true;
  }
  return false;
}
 
Example 4
Project: IM_Here   File: CircleImageView.java   View Source Code Vote up 6 votes
private void drawCircularImageViewBorder(Canvas canvas){
    Paint paint = new Paint();

    paint.setStyle(Paint.Style.STROKE);

    // set ARGB.
    final int RED = Color.red(borderColor);
    final int GREEN = Color.green(borderColor);
    final int BLUE = Color.blue(borderColor);
    final int ALPHA = Color.alpha(borderColor);

    paint.setStrokeWidth(borderSize);

    paint.setARGB(ALPHA, RED, GREEN, BLUE);

    canvas.drawCircle(radius + getXCenter(), radius + getYCenter(), radius, paint);
}
 
Example 5
Project: Rxjava2.0Demo   File: DoActivity.java   View Source Code Vote up 5 votes
private Bitmap drawCircle(Bitmap bm) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    int left = 0;
    int top = 0;
    int right = width;
    int bottom = height;
    int roundX = height / 2;
    if (width > height) {
        left = (width - height) / 2;
        top = 0;
        right = left + height;
        bottom = height;
    } else {
        left = 0;
        top = (height - width) / 2;
        right = width;
        bottom = top + width;
        roundX = width / 2;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Rect rect = new Rect(left, top, right, bottom);
    RectF rectF = new RectF(rect);

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setARGB(0, 0, 0, 0);
    paint.setColor(Color.GRAY);
    canvas.drawRoundRect(rectF, roundX, roundX, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bm,rect,rect,paint);
    bm.recycle();
    return bitmap;
}
 
Example 6
Project: SeafoodBerserker   File: MainFishView.java   View Source Code Vote up 5 votes
private void init(Context context) {
    if (!this.isInEditMode()) {

        splats[0] = BitmapFactory.decodeResource(getResources(), R.drawable.splat1);
        splats[1] = BitmapFactory.decodeResource(getResources(), R.drawable.splat2);
        splats[2] = BitmapFactory.decodeResource(getResources(), R.drawable.splat2);
        anchor[0] = BitmapFactory.decodeResource(getResources(), R.drawable.anchor_sm);
        axes[0] = BitmapFactory.decodeResource(getResources(), R.drawable.axe2);
        bgs[0] = BitmapFactory.decodeResource(getResources(), R.drawable.sea);
        fgtops[0] = BitmapFactory.decodeResource(getResources(), R.drawable.sail);
        fgbottoms[0] = BitmapFactory.decodeResource(getResources(), R.drawable.shipside2);

        final SurfaceHolder holder = getHolder();
        holder.addCallback(this);
        TypedArray fish = getResources().obtainTypedArray(R.array.fish);
        int[] values = getResources().getIntArray(R.array.points);
        totalValue = 0;
        for (int i = 0; i < fish.length(); i++) {
            FlyingItem item = new FlyingItem(BitmapFactory.decodeResource(getResources(), fish.getResourceId(i, 0)));
            item.setValue(values[i]);
            availableItems.add(item);
            totalValue += (100 - values[i]);
        }
        fish.recycle();

        this.setOnTouchListener(this);
        mLinePaint = new Paint();
        mLinePaint.setARGB(255, 255, 64, 64);
        mLinePaint.setStrokeWidth(5);
        mBGPaint = new Paint();
        mBGPaint.setARGB(255, 127, 127, 200);

        mTextPaint = new Paint();
        mTextPaint.setColor(Color.BLACK);
        mTextPaint.setShadowLayer(8,8,8,Color.WHITE);
        mTextPaint.setTextSize(80);

    }
}
 
Example 7
Project: PeSanKita-android   File: CanvasView.java   View Source Code Vote up 5 votes
/**
 * This method creates the instance of Paint.
 * In addition, this method sets styles for Paint.
 *
 * @return paint This is returned as the instance of Paint
 */
private Paint createPaint() {
  Paint paint = new Paint();

  paint.setAntiAlias(true);
  paint.setStyle(this.paintStyle);
  paint.setStrokeWidth(this.paintStrokeWidth);
  paint.setStrokeCap(this.lineCap);
  paint.setStrokeJoin(Paint.Join.MITER);  // fixed

  // for Text
  if (this.mode == Mode.TEXT) {
    paint.setTypeface(this.fontFamily);
    paint.setTextSize(this.fontSize);
    paint.setTextAlign(this.textAlign);
    paint.setStrokeWidth(0F);
  }

  if (this.mode == Mode.ERASER) {
    // Eraser
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    paint.setARGB(0, 0, 0, 0);

    // paint.setColor(this.baseColor);
    // paint.setShadowLayer(this.blur, 0F, 0F, this.baseColor);
  } else {
    // Otherwise
    paint.setColor(this.paintStrokeColor);
    paint.setShadowLayer(this.blur, 0F, 0F, this.paintStrokeColor);
    paint.setAlpha(this.opacity);
  }

  return paint;
}
 
Example 8
Project: airgram   File: ColorPicker.java   View Source Code Vote up 5 votes
private void init() {

        colorPointerPaint = new Paint();
        colorPointerPaint.setStyle(Style.STROKE);
        colorPointerPaint.setStrokeWidth(2f);
        colorPointerPaint.setARGB(128, 0, 0, 0);

        valuePointerPaint = new Paint();
        valuePointerPaint.setStyle(Style.STROKE);
        valuePointerPaint.setStrokeWidth(2f);

        valuePointerArrowPaint = new Paint();

        colorWheelPaint = new Paint();
        colorWheelPaint.setAntiAlias(true);
        colorWheelPaint.setDither(true);

        valueSliderPaint = new Paint();
        valueSliderPaint.setAntiAlias(true);
        valueSliderPaint.setDither(true);

        colorViewPaint = new Paint();
        colorViewPaint.setAntiAlias(true);

        colorViewPath = new Path();
        valueSliderPath = new Path();
        arrowPointerPath = new Path();

        outerWheelRect = new RectF();
        innerWheelRect = new RectF();

        colorPointerCoords = new RectF();

    }
 
Example 9
Project: LucaHome-MediaServer   File: GameState.java   View Source Code Vote up 5 votes
public void Draw(
        @NonNull Canvas canvas,
        @NonNull Paint paint) {
    canvas.drawRGB(20, 20, 20);
    paint.setARGB(255, 255, 255, 255);

    drawBall(canvas, paint);
    drawBoards(canvas, paint);
    drawPoints(canvas, paint);
    drawInfo(canvas, paint);
}
 
Example 10
Project: ascii_generate   File: AsciiRenderer.java   View Source Code Vote up 5 votes
public Bitmap createThumbnailBitmap(AsciiConverter.Result result) {
    int width = outputImageWidth / 4;
    int height = outputImageHeight / 4;
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setARGB(255, 255, 255, 255);

    canvas.drawARGB(255, 0, 0, 0);
    if (result != null) {
        for (int r = 0; r < result.rows; r += 2) {
            int ymin = height * r / result.rows;
            int ymax = height * (r + 2) / result.rows;
            for (int c = 0; c < result.columns; c += 2) {
                int xmin = width * c / result.columns;
                int xmax = width * (c + 2) / result.columns;
                float ratio = result.brightnessRatioAtRowColumn(r, c);
                paint.setColor(result.colorAtRowColumn(r, c));
                // for full color, always draw larger rectangle because colors will be darker
                if (result.getColorType() == AsciiConverter.ColorType.FULL_COLOR || ratio > 0.5) {
                    canvas.drawRect(xmin, ymin, xmax, ymax, paint);
                } else {
                    int x = (xmin + xmax) / 2 - 1;
                    int y = (ymin + ymax) / 2 - 1;
                    canvas.drawRect(x, y, x + 2, y + 2, paint);
                }
            }
        }
    }
    return bitmap;
}
 
Example 11
Project: mupdf-android-viewer-mini   File: PageView.java   View Source Code Vote up 5 votes
public PageView(Context ctx, AttributeSet atts) {
	super(ctx, atts);

	scroller = new Scroller(ctx);
	detector = new GestureDetector(ctx, this);
	scaleDetector = new ScaleGestureDetector(ctx, this);

	viewScale = 1;
	minScale = 1;
	maxScale = 2;

	linkPaint = new Paint();
	linkPaint.setARGB(32, 0, 0, 255);

	hitPaint = new Paint();
	hitPaint.setARGB(32, 255, 0, 0);

	errorPaint = new Paint();
	errorPaint.setARGB(255, 255, 80, 80);
	errorPaint.setStrokeWidth(5);
	errorPaint.setStyle(Paint.Style.STROKE);

	errorPath = new Path();
	errorPath.moveTo(-100, -100);
	errorPath.lineTo(100, 100);
	errorPath.moveTo(100, -100);
	errorPath.lineTo(-100, 100);
}
 
Example 12
Project: Muse-EEG-Toolkit   File: ConnectionStrengthView.java   View Source Code Vote up 5 votes
private static Paint paintForStrength(double strength) {
  Paint paint = new Paint();
  int r = (int)(255 * (1 - strength));
  int g = (int)(255 * strength);
  paint.setARGB(255, r, g, 0);
  paint.setStyle(Paint.Style.FILL_AND_STROKE);
  return paint;
}
 
Example 13
Project: Muse-EEG-Toolkit   File: Plot2DView.java   View Source Code Vote up 5 votes
private static Paint paintForAge(double age) {
  Paint paint = new Paint();
  int r = (int)(255 * (1 - age));
  int g = (int)(255 * age);
  paint.setARGB(255, r, g, 0);
  paint.setStyle(Paint.Style.FILL_AND_STROKE);
  return paint;
}
 
Example 14
Project: buildAPKsApps   File: ColorPicker.java   View Source Code Vote up 5 votes
private void init() {

        colorPointerPaint = new Paint();
        colorPointerPaint.setStyle(Style.STROKE);
        colorPointerPaint.setStrokeWidth(2f);
        colorPointerPaint.setARGB(128, 0, 0, 0);

        valuePointerPaint = new Paint();
        valuePointerPaint.setStyle(Style.STROKE);
        valuePointerPaint.setStrokeWidth(2f);

        valuePointerArrowPaint = new Paint();

        colorWheelPaint = new Paint();
        colorWheelPaint.setAntiAlias(true);
        colorWheelPaint.setDither(true);

        valueSliderPaint = new Paint();
        valueSliderPaint.setAntiAlias(true);
        valueSliderPaint.setDither(true);

        colorViewPaint = new Paint();
        colorViewPaint.setAntiAlias(true);

        colorViewPath = new Path();
        valueSliderPath = new Path();
        arrowPointerPath = new Path();

        outerWheelRect = new RectF();
        innerWheelRect = new RectF();

        colorPointerCoords = new RectF();

    }
 
Example 15
Project: buildAPKsApps   File: MultiColorPicker.java   View Source Code Vote up 5 votes
private void init() {

        colorPointerPaint = new Paint();
        colorPointerPaint.setStyle(Style.STROKE);
        colorPointerPaint.setStrokeWidth(2f);
        colorPointerPaint.setARGB(128, 0, 0, 0);

        valuePointerPaint = new Paint();
        valuePointerPaint.setStyle(Style.STROKE);
        valuePointerPaint.setStrokeWidth(2f);

        valuePointerArrowPaint = new Paint();

        colorWheelPaint = new Paint();
        colorWheelPaint.setAntiAlias(true);
        colorWheelPaint.setDither(true);

        valueSliderPaint = new Paint();
        valueSliderPaint.setAntiAlias(true);
        valueSliderPaint.setDither(true);

        colorViewPaint = new Paint();
        colorViewPaint.setAntiAlias(true);

        colorViewPath = new Path();
        valueSliderPath = new Path();
        arrowPointerPath = new Path();

        outerWheelRect = new RectF();
        innerWheelRect = new RectF();

        colorPointerCoords = new RectF();

    }
 
Example 16
Project: GSLayout   File: GSLayoutLine.java   View Source Code Vote up 5 votes
private void drawUnderline(Canvas canvas) {
    if (!(text instanceof Spanned)) {
        return;
    }
    Spanned spanned = (Spanned) text;
    UnderlineSpan[] spans = spanned.getSpans(start, end, UnderlineSpan.class);
    if (spans == null || spans.length == 0) {
        return;
    }
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(2); // TODO
    paint.setARGB(0xFF, 0, 0, 0); // TODO
    for (UnderlineSpan span : spans) {
        RectF spanRect = getRect(span);
        if (spanRect == null) {
            continue;
        }
        spanRect.offset(originX, originY);
        if (vertical) {
            float lineX = spanRect.left;
            canvas.drawLine(lineX, spanRect.top, lineX, spanRect.bottom, paint);
        } else {
            float lineY = (spanRect.bottom + originY) / 2;
            canvas.drawLine(spanRect.left, lineY, spanRect.right, lineY, paint);
        }
    }
}
 
Example 17
Project: GSLayout   File: GSLayoutLine.java   View Source Code Vote up 5 votes
private void drawStrikeThrough(Canvas canvas) {
    if (!(text instanceof Spanned)) {
        return;
    }
    Spanned spanned = (Spanned) text;
    StrikethroughSpan[] spans = spanned.getSpans(start, end, StrikethroughSpan.class);
    if (spans == null || spans.length == 0) {
        return;
    }
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(2); // TODO
    paint.setARGB(0xFF, 0, 0, 0); // TODO
    for (StrikethroughSpan span : spans) {
        RectF spanRect = getRect(span);
        if (spanRect == null) {
            continue;
        }
        spanRect.offset(originX, originY);
        if (vertical) {
            float lineX = (spanRect.left + spanRect.right) / 2;
            canvas.drawLine(lineX, spanRect.top, lineX, spanRect.bottom, paint);
        } else {
            float lineY = (spanRect.top + spanRect.bottom + originY) / 3;
            canvas.drawLine(spanRect.left, lineY, spanRect.right, lineY, paint);
        }
    }
}
 
Example 18
Project: Crimson   File: ScreenFilterService.java   View Source Code Vote up 4 votes
public MyFilterView(Context context) {
    super(context);

    mPaint = new Paint();
    mPaint.setARGB(200, 230, 0, 0);
}
 
Example 19
Project: buildAPKsSamples   File: GameView.java   View Source Code Vote up 4 votes
private static void setPaintARGBBlend(Paint paint, float alpha,
        int a1, int r1, int g1, int b1,
        int a2, int r2, int g2, int b2) {
    paint.setARGB(blend(alpha, a1, a2), blend(alpha, r1, r2),
            blend(alpha, g1, g2), blend(alpha, b1, b2));
}
 
Example 20
Project: EditPhoto   File: GlUtil.java   View Source Code Vote up 4 votes
public static int createTextureWithTextContent(String text) {
    // Create an empty, mutable bitmap
    Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_8888);
    // get a canvas to paint over the bitmap
    Canvas canvas = new Canvas(bitmap);
    canvas.drawARGB(0, 0, 255, 0);
    // get a background image from resources
    // note the image format must match the bitmap format
    //        Drawable background = context.getResources().getDrawable(R.drawable.background);
    //        background.setBounds(0, 0, 256, 256);
    //        background.draw(canvas); // draw the background to our bitmap
    // Draw the text
    Paint textPaint = new Paint();
    textPaint.setTextSize(32);
    textPaint.setAntiAlias(true);
    textPaint.setARGB(0xff, 0xff, 0xff, 0xff);
    // draw the text centered
    canvas.drawText(text, 16, 112, textPaint);

    int[] textures = new int[1];

    //Generate one texture pointer...
    GLES20.glGenTextures(1, textures, 0);

    //...and bind it to our array
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);

    //Create Nearest Filtered Texture
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
            GLES20.GL_NEAREST);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
            GLES20.GL_LINEAR);

    //Different possible texture parameters, e.g. GLES20.GL_CLAMP_TO_EDGE
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);

    //Alpha blending
    //GLES20.glEnable(GLES20.GL_BLEND);
    //GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    //Clean up
    bitmap.recycle();

    return textures[0];
}