Actionscript 3:如何仅清除图形对象的一部分

Actionscript 3:如何仅清除图形对象的一部分,actionscript,graphics,Actionscript,Graphics,我正在制作一个Flash CS5应用程序,其中用户在图像顶部的精灵上绘制透明覆盖层。用户需要能够像在MS Paint、Adobe Photoshop或GIMP中那样删除输入。因为精灵位于图像的顶部,所以我想不出安全的清晰颜色来覆盖用户刚刚擦过橡皮擦的部分 如何执行或模拟图形对象的部分清除?它实际上需要像矢量图形那样是精灵吗? 覆盖可能是位图对象吗?您想像MS paint中的画笔或橡皮擦那样进行像素级的颜色更改吗 如果你真的不需要矢量图形,我建议你改用位图对象。遵循以下步骤: 精灵覆盖实际上是位图

我正在制作一个Flash CS5应用程序,其中用户在图像顶部的精灵上绘制透明覆盖层。用户需要能够像在MS Paint、Adobe Photoshop或GIMP中那样删除输入。因为精灵位于图像的顶部,所以我想不出安全的清晰颜色来覆盖用户刚刚擦过橡皮擦的部分


如何执行或模拟图形对象的部分清除?

它实际上需要像矢量图形那样是精灵吗? 覆盖可能是位图对象吗?您想像MS paint中的画笔或橡皮擦那样进行像素级的颜色更改吗

如果你真的不需要矢量图形,我建议你改用位图对象。遵循以下步骤:

精灵覆盖实际上是位图覆盖,请确保其透明

var bmp : Bitmap = new Bitmap( new BitmapData(imgWidth, imgHeight, true, 0));
在临时精灵或事件形状中创建矢量图形,因为不需要包含

var tmpVectorGraphics : Shape = new Shape();
// draw whatever you want using the graphics library functions
drawStuffInShape(tmpVectorGraphics); 
现在在位图对象的bitmapdata上绘制矢量图形内容-在位图图形中转换矢量图形

bmp.bitmapData.draw(tmpVectorGraphics);
// if what you've drawn in the shape containing the vector graphics is overlayed
// the same way as the bmp object, you don't need to specify a matrix object
在此之后,可以清除TMPVector图形

tmpVectorGraphics.graphics.clear();
要像画图中的橡皮擦那样清除像素,可以创建透明形状并将其复制到位图中的特定位置

// create the eraser bitmap data
var eraser : BitmapData = new BitmapData(5, 5, true, 0);
// this is the location of where you want the eraser to be applied
var pos : Point = new Point (locationX, locationY); 
// apply the eraser to the main bmp overlay to a specific location
bmp.bitmapData.copyPixels(eraseer, eraser.rect, pos);
因此,只要您想添加一些图形,就可以在tmpVectorGraphics形状中生成它们,然后在位图对象上绘制。 这在性能方面也更快,因为创建形状时使用的图形命令越多,渲染每帧的成本就越高。位图缓存在内存中,不管其中的图形有多复杂

在actionscript中可以使用BitmapData做很多事情,而且在处理速度方面非常便宜,因此我建议您搜索一些BitmapData教程,因为如果您知道如何掌握这门课,您可以制作出令人惊叹的绘画应用程序:)

干杯,
Mihnea

它真的需要像矢量图形那样是精灵吗? 覆盖可能是位图对象吗?您想像MS paint中的画笔或橡皮擦那样进行像素级的颜色更改吗

如果你真的不需要矢量图形,我建议你改用位图对象。遵循以下步骤:

精灵覆盖实际上是位图覆盖,请确保其透明

var bmp : Bitmap = new Bitmap( new BitmapData(imgWidth, imgHeight, true, 0));
在临时精灵或事件形状中创建矢量图形,因为不需要包含

var tmpVectorGraphics : Shape = new Shape();
// draw whatever you want using the graphics library functions
drawStuffInShape(tmpVectorGraphics); 
现在在位图对象的bitmapdata上绘制矢量图形内容-在位图图形中转换矢量图形

bmp.bitmapData.draw(tmpVectorGraphics);
// if what you've drawn in the shape containing the vector graphics is overlayed
// the same way as the bmp object, you don't need to specify a matrix object
在此之后,可以清除TMPVector图形

tmpVectorGraphics.graphics.clear();
要像画图中的橡皮擦那样清除像素,可以创建透明形状并将其复制到位图中的特定位置

// create the eraser bitmap data
var eraser : BitmapData = new BitmapData(5, 5, true, 0);
// this is the location of where you want the eraser to be applied
var pos : Point = new Point (locationX, locationY); 
// apply the eraser to the main bmp overlay to a specific location
bmp.bitmapData.copyPixels(eraseer, eraser.rect, pos);
因此,只要您想添加一些图形,就可以在tmpVectorGraphics形状中生成它们,然后在位图对象上绘制。 这在性能方面也更快,因为创建形状时使用的图形命令越多,渲染每帧的成本就越高。位图缓存在内存中,不管其中的图形有多复杂

在actionscript中可以使用BitmapData做很多事情,而且在处理速度方面非常便宜,因此我建议您搜索一些BitmapData教程,因为如果您知道如何掌握这门课,您可以制作出令人惊叹的绘画应用程序:)

干杯,
Mihnea

我使用的是透明画笔,因此在绘制画笔之前,我需要擦除画笔后面的任何内容,否则画笔将覆盖自身。我尝试过的每种擦除方法都会在画笔周围留下瑕疵,无论是擦除太多还是太少。我怎样才能让它在我创建的形状后面准确地擦除?我当前的尝试创建了一个BlendMode.ALPHA位图,在画笔周围创建了一个剪切,但即使这样也不起作用。我使用的是透明画笔,因此在绘制画笔之前,我需要擦除画笔后面的任何内容,否则画笔将覆盖自身。我尝试过的每种擦除方法都会在画笔周围留下瑕疵,无论是擦除太多还是太少。我怎样才能让它在我创建的形状后面准确地擦除?我当前的尝试创建了一个BlendMode.ALPHA位图,在画笔周围创建了一个剪切,但即使这样也不起作用。