Java Code Examples for android.graphics.Canvas#drawRGB()

The following examples show how to use android.graphics.Canvas#drawRGB() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupConversation.java    From NaviBee with GNU General Public License v3.0 6 votes vote down vote up
private static Bitmap imageFromString(String svgAsString) throws SVGParseException {

        SVG svg = SVG.getFromString(svgAsString);

        // Create a bitmap and canvas to draw onto
        float   svgWidth = (svg.getDocumentWidth() != -1) ? svg.getDocumentWidth() : 500f;
        float   svgHeight = (svg.getDocumentHeight() != -1) ? svg.getDocumentHeight() : 500f;

        Bitmap  newBM = Bitmap.createBitmap(Math.round(svgWidth),
                Math.round(svgHeight),
                Bitmap.Config.ARGB_8888);
        Canvas bmcanvas = new Canvas(newBM);

        // Clear background to white if you want
        bmcanvas.drawRGB(255, 255, 255);

        // Render our document onto our canvas
        svg.renderToCanvas(bmcanvas);

        return newBM;
    }
 
Example 2
Source File: Tank3MotorView.java    From nxt-remote-control with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    canvas.drawRGB(0, 0, 0);
    Paint paint = new Paint();
    paint.setColor(0xff00ff00);
    paint.setStyle(Paint.Style.STROKE);
    
    float x0 = 0f;
    float x1 = mWidth*barWidth();
    float x2 = mWidth*(0.5f-barWidth()/2.0f);
    float x3 = mWidth*(0.5f+barWidth()/2.0f);
    float x4 = mWidth*(1-barWidth());
    float x5 = mWidth-1;
    canvas.drawRect(x0, mZero-mRange, x1, mZero+mRange, paint);
    canvas.drawRect(x2, mZero-mRange, x3, mZero+mRange, paint);
    canvas.drawRect(x4, mZero-mRange, x5, mZero+mRange, paint);
    for (int i = 0; i < 4; i++) {
        canvas.drawLine(x0, mZero+i/4f*mRange, x1, mZero+i/4f*mRange, paint);
        canvas.drawLine(x2, mZero+i/4f*mRange, x3, mZero+i/4f*mRange, paint);
        canvas.drawLine(x4, mZero+i/4f*mRange, x5, mZero+i/4f*mRange, paint);
        canvas.drawLine(x0, mZero-i/4f*mRange, x1, mZero-i/4f*mRange, paint);
        canvas.drawLine(x2, mZero-i/4f*mRange, x3, mZero-i/4f*mRange, paint);
        canvas.drawLine(x4, mZero-i/4f*mRange, x5, mZero-i/4f*mRange, paint);
    }
}
 
Example 3
Source File: TankView.java    From nxt-remote-control with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    canvas.drawRGB(0, 0, 0);
    Paint paint = new Paint();
    paint.setColor(0xff00ff00);
    paint.setStyle(Paint.Style.STROKE);
    
    float x0 = 0f;
    float x1 = mWidth*barWidth();
    float x2 = mWidth*(1-barWidth());
    float x3 = mWidth-1;
    canvas.drawRect(x0, mZero-mRange, x1, mZero+mRange, paint);
    canvas.drawRect(x2, mZero-mRange, x3, mZero+mRange, paint);
    for (int i = 0; i < 4; i++) {
        canvas.drawLine(x0, mZero+i/4f*mRange, x1, mZero+i/4f*mRange, paint);
        canvas.drawLine(x2, mZero+i/4f*mRange, x3, mZero+i/4f*mRange, paint);
        canvas.drawLine(x0, mZero-i/4f*mRange, x1, mZero-i/4f*mRange, paint);
        canvas.drawLine(x2, mZero-i/4f*mRange, x3, mZero-i/4f*mRange, paint);
    }
}
 
Example 4
Source File: TouchPadView.java    From nxt-remote-control with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    canvas.drawRGB(0, 0, 0);
    Paint paint = new Paint();
    paint.setColor(0xff00ff00);
    paint.setStyle(Paint.Style.STROKE);
    //canvas.drawLine(0, 0, mWidth, mHeight, paint);
    for (int i = 1; i<=6; i++) {
        //canvas.drawCircle(mCx, mCy, mRadius*i/6.0f, paint);
        canvas.drawArc(new RectF(mCx-mRadius*i/6.0f, mCy-mOffset-mRadius*i/6.0f, mCx+mRadius*i/6.0f, mCy-mOffset+mRadius*i/6.0f), 180f, 180f, false, paint);
        canvas.drawArc(new RectF(mCx-mRadius*i/6.0f, mCy+mOffset-mRadius*i/6.0f, mCx+mRadius*i/6.0f, mCy+mOffset+mRadius*i/6.0f), 0f, 180f, false, paint);
    }
    canvas.drawLine(mCx+0.16666f*mRadius, mCy-mOffset, mCx+mRadius, mCy-mOffset, paint);
    canvas.drawLine(mCx-0.16666f*mRadius, mCy-mOffset, mCx-mRadius, mCy-mOffset, paint);
    canvas.drawLine(mCx+0.16666f*mRadius, mCy+mOffset, mCx+mRadius, mCy+mOffset, paint);
    canvas.drawLine(mCx-0.16666f*mRadius, mCy+mOffset, mCx-mRadius, mCy+mOffset, paint);
    canvas.drawLine(mCx, mCy+mOffset+0.16666f*mRadius, mCx, mCy+mOffset+mRadius, paint);
    canvas.drawLine(mCx, mCy-mOffset-0.16666f*mRadius, mCx, mCy-mOffset-mRadius, paint);
    canvas.drawLine(mCx+0.16666f*mRadius*0.70710f, mCy+mOffset+0.16666f*mRadius*0.70710f, mCx+mRadius*0.70710f, mCy+mOffset+mRadius*0.70710f, paint);
    canvas.drawLine(mCx-0.16666f*mRadius*0.70710f, mCy+mOffset+0.16666f*mRadius*0.70710f, mCx-mRadius*0.70710f, mCy+mOffset+mRadius*0.70710f, paint);
    canvas.drawLine(mCx+0.16666f*mRadius*0.70710f, mCy-mOffset-0.16666f*mRadius*0.70710f, mCx+mRadius*0.70710f, mCy-mOffset-mRadius*0.70710f, paint);
    canvas.drawLine(mCx-0.16666f*mRadius*0.70710f, mCy-mOffset-0.16666f*mRadius*0.70710f, mCx-mRadius*0.70710f, mCy-mOffset-mRadius*0.70710f, paint);
}
 
Example 5
Source File: RSCBitmapSurfaceView.java    From Game with GNU General Public License v3.0 5 votes vote down vote up
private void doDraw(Canvas c) {
	if (gameActivity.getMudclient() == null) {
		return;
	}
	c.drawRGB(0, 0, 0);
	int resizedWidth = c.getWidth();
	int resizedHeight = c.getHeight();
	c.scale(((float) resizedWidth / (float) gameActivity.getMudclient().getGameWidth()),
		((float) resizedHeight / (float) (gameActivity.getMudclient().getGameHeight() + 12)));
	c.drawBitmap(currentFrame, 0, 0, bitmapPaint);
}
 
Example 6
Source File: GameSurfaceView.java    From homescreenarcade with GNU General Public License v3.0 5 votes vote down vote up
public void drawGame(Canvas canvas) {
        canvas.drawRGB(0, 0, 0);
        drawMaze(canvas); // draw updated maze
        drawPacmon(canvas);
        drawGhost(canvas);
//        drawScore(canvas);
    }
 
Example 7
Source File: ShaderImageView.java    From jmessage-android-uikit with MIT License 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas) {
    if(DEBUG) {
        canvas.drawRGB(10, 200, 200);
    }

    if(!getPathHelper().onDraw(canvas)) {
        super.onDraw(canvas);
    }

}
 
Example 8
Source File: ShaderImageView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas) {
    if(DEBUG) {
        canvas.drawRGB(10, 200, 200);
    }

    if(!getPathHelper().onDraw(canvas)) {
        super.onDraw(canvas);
    }

}
 
Example 9
Source File: ShaderImageView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas) {
    if(DEBUG) {
        canvas.drawRGB(10, 200, 200);
    }

    if(!getPathHelper().onDraw(canvas)) {
        super.onDraw(canvas);
    }

}
 
Example 10
Source File: RenderFromSurfaceActivity.java    From AndroidVideoSamples with Apache License 2.0 4 votes vote down vote up
@Override
public void renderFrame( Canvas canvas, long time, long interval ) {
   canvas.drawRGB( (int) ( Math.random() * 255 ), (int) ( Math.random() * 255 ), (int) ( Math.random() * 255 ) );
}