是否可以使用一种drawCircle方法在Android的画布上绘制一个具有不同颜色边框的圆圈?
我注意到了FILL_AND_STROKE的PaintStyle,但是填充和边框似乎都没有不同的颜色.
我真的不想要调用两个drawCircle方法.
首先,这是一个最初在这里提出的跟进问题,在Android中平移,缩放和缩放自定义的Canvas绘图视图
由于还没有答案,我终于使用android-gesture-detector解决了我的问题
应用缩放/缩放手势后,我发现,画布绘制坐标仍然指向旧位置(在应用缩放之前),而不是绘制完全相同的触摸坐标.基本上,在缩放或拖动画布后,我无法获得正确的画布坐标.
在缩放之前,
缩小后,触摸点将绘制在之前的位置.我希望它能够在当前触摸位置上绘制,
示例代码,
public class DrawingView extends View {
private void setupDrawing() {
mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener());
mgd = new MoveGestureDetector(ctx, mgl);
sgd = new ScaleGestureDetector(ctx, sgl);
rgd = new RotateGestureDetector(ctx, rgl);
}
class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
mScaleFactor *= detector.getScaleFactor();
// Don't let the object get too small or too large.
mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 5.0f));
invalidate();
return true;
}
}
MoveGestureDetector.SimpleOnMoveGestureListener mgl = new …Run Code Online (Sandbox Code Playgroud) android android-canvas android-view android-gesture android-touch-event
我想在画布上绘制带刻度线的圆圈.
圆圈包含100个刻度.但是在1到2之间存在比其他更多的子刻度,我还想根据用户输入(圆周旋转)计算刻度.请帮我..

我试过这个http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/
private void drawScale(Canvas canvas) {
//canvas.drawOval(scaleRect, scalePaint);
canvas.drawCircle(0.5f,0.5f, 0.49f,scalePaint);
canvas.save(Canvas.MATRIX_SAVE_FLAG);
for (i = 0; i < totalNicks; ++i) {
float y1 = scaleRect.top;
float y2 = y1 - 0.020f;
//canvas.drawLine(0.5f, y1, 0.5f, y2, scalePaint);
if (i % 1 == 0) {
int value = nickToDegree(i);
if(value<=360)
{
float y3 = 0;
scaleText =new Paint();
scaleText.setTextSize(0.035f);
scaleText.setColor(Color.BLACK);
scaleText.setTypeface(Typeface.DEFAULT_BOLD);
scaleText.setTextScaleX(0.8f);
scaleText.setTextAlign(Paint.Align.CENTER);
scaleText.setStrokeWidth(0.015f);
scaleText.setAntiAlias(true);
scaleline =new Paint();
scaleline.setStyle(Paint.Style.FILL);
scaleline.setColor(Color.BLACK);
scaleline.setStrokeWidth(0.005f);
scaleline.setAntiAlias(true);
switch …Run Code Online (Sandbox Code Playgroud) 我没有太多的运气包围我的头,所以我希望有人可以帮助我.
我使用svg-android从SVG获得了一个drawable,但是drawable没有缩放到视图.我能够找到的所有内容都说我应该直接绘制到画布并重新缩放画布,但是当我尝试它时,它似乎只是改变边界而不是缩放图像.
这是我到目前为止所尝试的:
ImageView testview = (ImageView)findViewById(R.id.testview);
//Get SVG and convert to drawable
SVG vector = SVGParser.getSVGFromResource(getResources(),R.drawable.testvector);
Drawable test = vector.createPictureDrawable();
testview.setBackground(test); //displays fine, but won't scale to the dimensions of
//the View
//function that clips the image but doesn't scale:
Drawable testTwo = new CustomPictureDrawable(vector.getPicture(),
(float)0.5, (float)0.5);
testView.setBackground(testTwo);
class CustomPictureDrawable extends PictureDrawable {
private float scalex, scaley;
public CustomPictureDrawable(Picture picture, float scalex, float scaley) {
super(picture);
this.scalex = scalex;
this.scaley = scaley;
}
@Override
public void draw(Canvas canvas) { …Run Code Online (Sandbox Code Playgroud) 我试图在我的位图周围创建一个圆形框架!

使用此代码,我可以使我的位图圆形:
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff4242DB;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = bitmap.getWidth()/2;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
//canvas.drawCircle(0, 0, bitmap.getWidth(), paint);
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
Run Code Online (Sandbox Code Playgroud)
我试过的是用画布绘制一个圆圈(outcommented line),但它没有结果.有谁知道如何在它周围添加圆形边框?
编辑
当我使用该行时:
canvas.drawCircle(0, 0, …Run Code Online (Sandbox Code Playgroud) 我有一个画布应用程序.我正在尝试用Canvas+ 创建一个签名应用程序onTouchListener.
这是我的保存方法,我尝试将签名保存到图像:
private void save() {
hideMenuBar();
View content = this;
content.setDrawingCacheEnabled(true);
content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap bitmap = content.getDrawingCache();
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
String imgPath = path+"/imotax/capture/spop/ttd/image" + "temp" + ".jpg";
File file = new File(imgPath);
FileOutputStream ostream;
try {
file.createNewFile();
ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.flush();
ostream.close();
Toast.makeText(getContext(), "image saved", 5000).show();
} catch (Exception e) {
e.printStackTrace();
Log.i("ttd", e.toString());
Toast.makeText(getContext(), "Failed To Save", 5000).show();
showMenuBar();
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,但它总是错误或进入catch带有此错误的语句:
java.io.IOException: open failed: ENOENT …Run Code Online (Sandbox Code Playgroud) 我尝试使用以下代码
问题 - 当我尝试保存图像时,它显示空指针错误,并且没有保存任何内容.
请帮助我找到代码的问题或建议我一个替代方案,这是非常相似的.提前致谢.
在画布上绘制的代码:
package com.example.draw2;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
public class MyDrawView extends View {
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
private Paint mBitmapPaint;
private Paint mPaint;
public MyDrawView(Context c, AttributeSet attrs) {
super(c, attrs);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(0xFF000000);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(9);
}
@Override
protected void …Run Code Online (Sandbox Code Playgroud) 在绘制路径时,我遇到了Android Canvas的一些问题.我的情况是我有一个相对布局工作,如地图视图(不使用谷歌API或类似的东西).我必须在该视图上绘制一条路径.
canvas.drawPath(polyPath, borderPaint);
Run Code Online (Sandbox Code Playgroud)
我还必须使用画布绘制其他类型的圆形,多边形.每次我们放大或缩小时,我们都会重新计算路径点以匹配缩放级别.当使用像Android 2.3.3这样的旧api时,根本没有问题.但是对于像android 4.x这样的新api,当我们放大时,有一些点位于可见视图之外(例如-300,-300).放大一段时间后,可见区域只显示我路径的一小部分.然后突然整条路径消失了.如果我们缩小,它会再次出现.就像画布停止渲染那些(其他对象仍然显示像图标)同样的东西去圆形,椭圆形或多边形.
所以我不确定帆布画的东西是否有任何改变?关于使用画布绘画,我有什么遗漏吗?
什么是将Rect变量转换为RectF变量的最佳方法?我无法施展它.
RectF rect = (RectF) currentRect; //produces an error
Run Code Online (Sandbox Code Playgroud) Android画布改变颜色
我有一个有两个视图的应用程序
<com.myexample.ui.view.BackgroundView
android:id="@+id/id_draw_canvas_classroom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
android:background="#FFFFFFFF" />
<com.myexample.ui.view.FrontView
android:id="@+id/id_draw_canvas_user"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
android:background="#00000000" />
Run Code Online (Sandbox Code Playgroud)
这些视图是重叠的,并且在一段时间内我在背景视图中加载信息.在此期间,我想将FrontView设置为白色,然后(当背景完成加载时)变为透明.
在FrontView中,我有一个带位图的Canvas.正在工作,如果我想将背景设置为透明,我可以这样做
canvas.drawColor(0);
Run Code Online (Sandbox Code Playgroud)
将背景设置为白色
canvas.drawColor(-1);
Run Code Online (Sandbox Code Playgroud)
但我无法改变透明白色.
谢谢