最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android使用貝塞爾曲線畫心形

 更新時間:2022年06月29日 15:07:52   作者:「已注銷」  
這篇文章主要為大家詳細(xì)介紹了Android使用貝塞爾曲線畫心形,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android使用貝塞爾曲線畫心形的具體代碼,供大家參考,具體內(nèi)容如下

一開始我只是想畫個圓,可畫著畫著就成了心形,那就將錯就錯

1. 創(chuàng)建一個Activity

RelativeLayout container = findViewById(R.id.download_container);

? ? DisplayMetrics metrics = new DisplayMetrics();
? ? getWindowManager().getDefaultDisplay().getMetrics(metrics);
? ? deviceWidth = metrics.widthPixels;
? ? deviceHeight = metrics.heightPixels;

? ? Circle circle = new Circle(this, deviceWidth / 2, deviceHeight / 2, deviceWidth / 8);
? ? Line line = new Line(this, deviceWidth / 2, deviceHeight / 2, deviceWidth / 8);
? ? container.addView(line);

2. 創(chuàng)建一個自定義的View

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.view.View;

public class Line extends View {

? ? private Paint mPaint;
? ? private PointF startPointF;
? ? private PointF endPointF;
? ? private PointF controlPointF1, controlPointF2;

? ? private PointF startPointF2;
? ? private PointF endPointF2;
? ? private PointF controlPointF3, controlPointF4;

? ? public Line(Context context, float x, float y, float radius) {
? ? ? ? super(context);
? ? ? ? double d = (2 * Math.sqrt(2) - 1);
? ? ? ? this.startPointF = new PointF(x, y - radius);
? ? ? ? this.endPointF = new PointF(x, y + radius / 10);
? ? ? ? this.controlPointF1 = new PointF(x, (float) (y - d * radius));
? ? ? ? this.controlPointF2 = new PointF((float) (x + d * radius), (float) (y - d * radius));

? ? ? ? this.startPointF2 = new PointF(x, y - radius);
? ? ? ? this.endPointF2 = new PointF(x, y + radius / 10);
? ? ? ? this.controlPointF3 = new PointF(x, (float) (y - d * radius));
? ? ? ? this.controlPointF4 = new PointF((float) (x - d * radius), (float) (y - d * radius));

? ? ? ? this.mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
? ? ? ? this.mPaint.setColor(Color.WHITE);
? ? }

? ? @Override
? ? protected void onDraw(Canvas canvas) {
? ? ? ? super.onDraw(canvas);

? ? ? ? //繪制貝塞爾曲線
? ? ? ? Path path = new Path();

? ? ? ? path.moveTo(startPointF.x, startPointF.y);
? ? ? ? path.cubicTo(controlPointF1.x, controlPointF1.y, controlPointF2.x, controlPointF2.y, endPointF.x, endPointF.y);
? ? ? ? canvas.drawPath(path, mPaint);

? ? ? ? path.moveTo(startPointF2.x, startPointF2.y);
? ? ? ? path.cubicTo(controlPointF3.x, controlPointF3.y, controlPointF4.x, controlPointF4.y, endPointF2.x, endPointF2.y);
? ? ? ? canvas.drawPath(path, mPaint);
? ? }
}

運(yùn)行效果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

仪征市| 平湖市| 江陵县| 龙胜| 搜索| 盐池县| 梅河口市| 青神县| 乐东| 志丹县| 嘉义市| 泸溪县| 盘山县| 华阴市| 刚察县| 德钦县| 宁南县| 洛阳市| 广德县| 衡山县| 马公市| 碌曲县| 怀柔区| 皋兰县| 射洪县| 黔西| 镇沅| 孝感市| 马尔康县| 蕲春县| 且末县| 绥芬河市| 龙井市| 延边| 霸州市| 遂溪县| 乌什县| 时尚| 游戏| 焉耆| 峡江县|