问题描述
即时通讯使用低于code画上,而手指触摸的举动......我在这里公布的部分code,这是工作的罚款..位帆布行
如下面的图像,黑白位图抹去触摸拖动。我帆布制成透明的,所以家长布局背景(彩色图像)越来越明显。
我想知道,有多少面积被删除(如50%或位图的60%)..有没有办法找到?
//删除油漆
mDrawPaint =新的油漆();
mDrawPaint.setAntiAlias(真正的);
mDrawPaint.setDither(真正的);
mDrawPaint.setStyle(Paint.Style.STROKE);
mDrawPaint.setStrokeJoin(Paint.Join.ROUND);
mDrawPaint.setStrokeCap(Paint.Cap.ROUND);
mDrawPaint.setStrokeWidth(50);
mDrawPaint.setXfermode(新PorterDuffXfermode(PorterDuff.Mode.CLEAR));
BlurMaskFilter运动模糊=新BlurMaskFilter(10,BlurMaskFilter.Blur.NORMAL);
mDrawPaint.setMaskFilter(运动模糊);
私人无效doDraw(帆布C){
c.drawBitmap(mBitmap,0,0,NULL);
}
私人浮动MX,我的;
私有静态最终浮动TOUCH_TOLERANCE = 1;
无效touch_start(浮X,浮动Y){
mPath.reset();
mPath.moveTo(X,Y);
MX = X;
我= Y;
}
无效TOUCH_MOVE(浮X,浮动Y){
浮DX = Math.abs(X - MX);
浮DY = Math.abs(Y - 我的);
如果(DX> = TOUCH_TOLERANCE || DY> = TOUCH_TOLERANCE){
mPath.quadTo(MX,MY,(X + MX)/ 2,(Y +我)/ 2);
MX = X;
我= Y;
}
canvas.drawPath(的mpath,mDrawPaint); //删除黑白图像
}
无效touch_up(){
mPath.lineTo(MX,MY);
//提交路径,我们的屏幕外
mCanvas.drawPath(的mpath,mDrawPaint);
//杀了这个,所以我们不重复抽奖
mPath.reset();
}
尝试使用蒙特卡罗方法估计百分比的透明区域。我认为这是做这是一个最快,最简单的方法。取约50(取决于精度需要)随机像素上的透明面罩,并检查它们的颜色。然后计算ANS = TransparentPixelsCount / TestPixelCount。
这是很难计算使用路径坐标用户的图纸广场。这是相当长的遍历所有像素。因此,恕我直言蒙特卡洛是您最佳的选择。
Im using below code to draw line on bitmap canvas while finger touch move... here i posted partial code and it is working fine..
As shown in below image, the black and white bitmap erased on touch drag.. I made canvas transparent so the parent layout background(color image) is getting visible.
I want to know , how much area is erased(like 50% or 60% of bitmap ).. is there any way to find that?
//Erasing paint
mDrawPaint = new Paint();
mDrawPaint.setAntiAlias(true);
mDrawPaint.setDither(true);
mDrawPaint.setStyle(Paint.Style.STROKE);
mDrawPaint.setStrokeJoin(Paint.Join.ROUND);
mDrawPaint.setStrokeCap(Paint.Cap.ROUND);
mDrawPaint.setStrokeWidth(50);
mDrawPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
BlurMaskFilter mBlur = new BlurMaskFilter(10, BlurMaskFilter.Blur.NORMAL);
mDrawPaint.setMaskFilter(mBlur);
private void doDraw(Canvas c) {
c.drawBitmap(mBitmap, 0, 0,null );
}
private float mX, mY;
private static final float TOUCH_TOLERANCE = 1;
void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}
void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
mX = x;
mY = y;
}
canvas.drawPath(mPath, mDrawPaint ); //Erasing Black and white image
}
void touch_up() {
mPath.lineTo(mX, mY);
// commit the path to our offscreen
mCanvas.drawPath(mPath, mDrawPaint);
// kill this so we don't double draw
mPath.reset();
}
Try to use Monte Carlo method to estimate percentage of transparent area. I think it is a fastest and easiest way to do this. Take about 50 (depends on accuracy you need) random pixels on your transparency mask and check their color. Then calc ans = TransparentPixelsCount/TestPixelCount.
It is very hard to calculate square of user's drawings using path coordinates. And it's quite long to iterate over all pixels. So, IMHO Monte Carlo is your choise.
这篇关于如何获得总覆盖面积,同时绘制在画布上的android路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!