paint,canvas繪畫出來的各種形狀

2021-09-30 04:40:25 字數 2165 閱讀 9404

package com.my.activity.graphic;

import android.content.context;

import android.graphics.canvas;

import android.graphics.color;

import android.graphics.lineargradient;

import android.graphics.paint;

import android.graphics.path;

import android.graphics.rectf;

import android.graphics.shader;

import android.os.bundle;

import android.view.view;

import com.my.mainactivity;

import com.my.r;

/*** 各種型別的圖形

*@author  owen

*@2010-8-19

*@下午04:05:07

*/public class graphicesactivity extends mainactivity

/* 自定義繼承view 的myview*/

private class myview extends view

/*重寫ondraw()*/

@override

protected void ondraw(canvas canvas)

,null,shader.tilemode.repeat);

paint.setshader(mshader);

/*畫乙個漸變色圓*/

canvas.drawcircle(200,40,30, paint);

/*畫乙個漸變色正方形*/

canvas.drawrect(170, 90, 230, 150, paint);

/*畫乙個漸變色長方形*/

canvas.drawrect(170, 170, 230,200, paint);

/*畫乙個漸變色橢圓*/

rectf re3=new rectf(170,220,230,250);

canvas.drawoval(re3, paint);

/*畫乙個漸變色三角形*/

path path4=new path();

path4.moveto(170,330);

path4.lineto(230,330);

path4.lineto(200,270);

path4.close();

canvas.drawpath(path4, paint);

/*畫乙個漸變色梯形*/

path path5=new path();

path5.moveto(170, 410);

path5.lineto(230,410);

path5.lineto(215,350);

path5.lineto(185, 350);

path5.close();

canvas.drawpath(path5, paint);

/*寫字*/

paint.settextsize(24);

canvas.drawtext(getresources().getstring(r.string.str_text1), 240, 50, paint);

canvas.drawtext(getresources().getstring(r.string.str_text2), 240, 120, paint);

canvas.drawtext(getresources().getstring(r.string.str_text3), 240, 190, paint);

canvas.drawtext(getresources().getstring(r.string.str_text4), 240, 250, paint);

canvas.drawtext(getresources().getstring(r.string.str_text5), 240, 320, paint);

canvas.drawtext(getresources().getstring(r.string.str_text6), 240, 390, paint);  }}

}

paint Canvas畫筆 畫布

1.建立畫筆 paint paint new paint 設定畫筆的顏色 paint.setcolor color.red 2.建立乙個向量圖bitmap 向量圖 vector 也叫做向量圖,簡單的說,就是縮放不失真的影象格式。建立乙個向量圖bitmap bitmap bitmap bitmap.c...

OpenCv 繪畫函式

opencv提供在影象上繪畫功能,比如線 矩陣 圓 文字等等。具體如下 畫線import numpy as np import cv2 as cv 建立一塊面板 img np.zeros 512,512,3 np.uint8 畫一條線,從 0,0 到 511,511 紅色的線,5畫素寬 cv.lin...

星空繪畫系統

chrome瀏覽器 window 10 vs code h5 canvas jquery框架 碼繪和手繪是不同的藝術形式。如今,和計算機的互動方式越來越多元化,除了滑鼠鍵盤操作以外,數字板 leap motion動作捕捉裝置 vr頭盔等等新型互動裝置也逐漸興起。在追求傳統繪畫的同時,也需要順應技術發...