您好,在此先感谢,这里我想制作imageview六边形或五边形我参考本教程,但我无法修改点。因此,旋转六角形90度或任何其他方式所需的任何变化。我使用以下代码的六边形,但这个代码给了我六边形,但我想要相同的输出90度旋转。
public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
Bitmap finalBitmap;
if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius,
false);
else
finalBitmap = bitmap;
Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),finalBitmap.getHeight(),Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
finalBitmap.getHeight());
Point point1_draw = new Point(75, 0);
Point point2_draw = new Point(0, 50);
Point point3_draw = new Point(0, 100);
Point point4_draw = new Point(75, 150);
Point point5_draw = new Point(150, 100);
Point point6_draw = new Point(150, 50);
Path path = new Path();
path.moveTo(point1_draw.x, point1_draw.y);
path.lineTo(point2_draw.x, point2_draw.y);
path.lineTo(point3_draw.x, point3_draw.y);
path.lineTo(point4_draw.x, point4_draw.y);
path.lineTo(point5_draw.x, point5_draw.y);
path.lineTo(point6_draw.x, point6_draw.y);
path.close();
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawPath(path, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(finalBitmap, rect, rect, paint);
return output;
}
答案 0 :(得分:0)
使用此库: - https://github.com/MostafaGazar/CustomShapeImageView
希望这会对你有所帮助。 :)
答案 1 :(得分:0)
您可以在绘制前将画布旋转90度,并在绘制后将其恢复。
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.rotate(90);//or -90
//Do drawing here
//canvas.drawPath(...)
canvas.restore();
答案 2 :(得分:0)
canvas.save();
canvas.rotate(90,90,90);
//画画布 canvas.drawPath(path,paint);
canvas.restore();