林你的意思是不知道,但我认为你正在试图做的是用户是能够放入形状或它会自动创建形状。您可以使用希望提供为出发点这个链接,您可以设置以下的第二个链接:)
https://examples.javacodegeeks.com/android/core/graphics/canvas-graphics/android-canvas-example/
https://developer.android.com/reference/android/graphics/Canvas.html
void drawOval(float left, float top, float right, float bottom, Paint paint)
或者像这样
不同的形状
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
if (scaleBitmapImage == null) {
return null;
}
int sourceWidth = scaleBitmapImage.getWidth();
int sourceHeight = scaleBitmapImage.getHeight();
int targetWidth = Math.min(sourceWidth, sourceHeight);
int targetHeight = targetWidth;
Bitmap targetBitmap = Bitmap.createBitmap(
targetWidth,
targetHeight,
Bitmap.Config.ARGB_8888
);
Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.addCircle(
((float) targetWidth - 1)/2,
((float) targetHeight - 1)/2,
Math.min(((float) targetWidth), ((float) targetHeight))/2,
Path.Direction.CCW
);
canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(
sourceBitmap,
new Rect(0, 0, sourceBitmap.getWidth(),
sourceBitmap.getHeight()),
new Rect(0, 0, targetWidth, targetHeight),
null
);
return targetBitmap;
}
来源:http://www.programcreek.com/java-api-examples/index.php?api=android.graphics.Canvas
该类不会在Android以外的GUI中绘制,尽管 –
@ cricket_007我不想绘制GUI,我想要的是创建画布并像绘制drawAine一样绘制它,然后将其另存为位图 – Michal
和Graphics2D已经可以做到这一点,或多或少 https://stackoverflow.com/questions/8202253/saving-a-java-2d-graphics-image-as-png-file –