试图实现图像的徒手裁剪,所以我能够在图像上绘图.但它超出了位图区域.我只想限制用户只能在位图区域内绘制,检查下面的屏幕截图.
我正在尝试实现像Photoshop套索工具这样的功能.
它在视图区域外绘制,产生不正确的输出.

产量

码@
的onDraw
public void onDraw(Canvas canvas) {
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
canvas.drawBitmap(bitmap, rect, rect, null);
// RectF r = new RectF();
// Matrix matrix = new Matrix();
// matrix.mapRect(r);
// Log.i(TAG, "Rect " + r.left + " " + r.top + " " + r.right + " " +
// r.bottom + " ");
// canvas.clipRect(r.left, r.top, r.right, r.bottom);
Path path = new Path();
boolean first = true;
for …Run Code Online (Sandbox Code Playgroud) 即时尝试使用canvas在android中实现徒手作物.我使用drawPath并将其存储在List中并在画布路径绘图中绘制确定,
像这样

但现在我想用这段代码在侧面区域中制作所有像素,但我不知道如何做到这一点..
public Bitmap getBitmapWithTransparentBG(Bitmap srcBitmap)
{
Bitmap result = srcBitmap.copy(Bitmap.Config.ARGB_8888, true);
int nWidth = result.getWidth();
int nHeight = result.getHeight();
for (int y = 0; y < nHeight; ++y)
{
for (int x = 0; x < nWidth; ++x)
{
for (int i = 0; i < points.size() ; i++)
{
}
result.setPixel(x, y, Color.TRANSPARENT);
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
points是路径坐标列表,是绘制路径的代码
package com.org;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color; …Run Code Online (Sandbox Code Playgroud) 我想在Image上做自由裁剪风格......
图像可以来自图库,也可以来自相机......
对此有什么解决方案吗?