【发布时间】:2014-08-08 05:44:52
【问题描述】:
我成功地裁剪了圆形图像。但现在我想以编程方式在它周围添加圆形红色边框。 我尝试了很多东西来使用我拥有的代码,但它不起作用。 这是进行裁剪的类的代码
enter code here
import android.R.color;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
/**
* GraphicsUtil an utility class which convert the image in circular shape
*/
public class GraphicsUtil {
/*
* Draw image in circular shape Note: change the pixel size if you want
* image small or large
*/
public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
// TODO Auto-generated method stub
int targetWidth = 400;
int targetHeight = 400;
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.addCircle(((float) targetWidth) / 2, ((float) targetHeight) / 2,
(Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
Path.Direction.CW);
Paint paint = new Paint();
paint.setColor(Color.GRAY);
// paint.setStyle(Paint.Style.STROKE);
Paint p = new Paint();
p.setColor(color.white);
p.setStyle(Paint.Style.STROKE);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
paint.setDither(true);
paint.setFilterBitmap(true);
canvas.drawOval(new RectF(0, 0, targetWidth, targetHeight), paint);
// paint.setColor(Color.TRANSPARENT);
canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(),
sourceBitmap.getHeight()), new RectF(0, 0, targetWidth,
targetHeight), paint);
return targetBitmap;
}
}
【问题讨论】:
标签: java android image border crop