在Android中绘制自定义形状拖到画布 [英] Drawing custom shape onto Canvas in Android

查看:149
本文介绍了在Android中绘制自定义形状拖到画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经被这一个有点难倒了,所以我想我会问这里看看如果任何人有任何指针。

在简单地说,我有一个应用程序,我想多复杂的形状被绘制到画布上,然后将被绘制到屏幕上(我将实现围绕在这个问题的回答提出的大帆布平移: 安卓:绘画和旋转的画布

我去究竟是如何做有关创建自定义形状和Android中的任意位置/旋转绘制它在画布?

下面是一个简单的自定义形状的例子,因为我已经尽力实现它至今(通常他们会在运行时创建的)

 公共类符号{
    公共位图B = Bitmap.createBitmap(500,500,Bitmap.Config.ARGB_8888);
    公共符号(){
        帆布帆布=新的Canvas(二);;
        涂料粉刷=新的油漆();
        paint.setColor(Color.GRAY);
        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(25);
        paint.setStrokeWidth(4);
        paint.setDither(真);
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStrokeCap​​(Paint.Cap.ROUND);
        paint.setAntiAlias​​(真);
        字符串str =TestStr;
        canvas.drawText(STR,250,250,油漆);
    }
}


解决方案

哇,我derped在这一个铁杆。

<一个href=\"http://stackoverflow.com/questions/5186212/android-canvas-drawbitmap-performance-issue\">Android:

canvas.drawBitmap性能问题

在我的主类造万物加入这个快乐的,至少就这个简单的例子了:

 符号s =新符号();
canvas.save();
canvas.rotate(5);
canvas.drawBitmap(S.B,0,0,NULL);
canvas.restore();

I've been stumped by this one for a little bit, so I figured I'd ask here to see if anyone has any pointers.

In a nutshell, I have an app where I want multiple complex shapes to be drawn onto a canvas, which will then be drawn onto the screen (I'll be implementing panning around the large canvas as suggested in this question's answer: Android: Drawing and rotating on a canvas)

How exactly do I go about creating a custom shape and drawing it at arbitrary locations/rotations on a Canvas in Android?

Below is an example of a simple custom shape, as I've tried to implement it so far (typically they'd be created at run-time)

public class Symbol {
    public Bitmap b = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
    public Symbol() {
        Canvas canvas = new Canvas(b);;
        Paint paint = new Paint();
        paint.setColor(Color.GRAY);
        paint.setStyle(Paint.Style.STROKE);
        paint.setTextSize(25);
        paint.setStrokeWidth(4);
        paint.setDither(true);                    
        paint.setStrokeJoin(Paint.Join.ROUND);    
        paint.setStrokeCap(Paint.Cap.ROUND);      
        paint.setAntiAlias(true);  
        String str="TestStr";
        canvas.drawText(str, 250,250, paint);
    }
}

解决方案

Wow, I derped hardcore on this one.

Android: canvas.drawBitmap performance issue

Adding this in my main class made everything happy, at least as far as this simple case went.:

Symbol s = new Symbol();
canvas.save();
canvas.rotate(5);
canvas.drawBitmap(s.b, 0,0, null);
canvas.restore();

这篇关于在Android中绘制自定义形状拖到画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆