AS3 photoshop brushes

。_饼干妹妹 提交于 2019-12-24 22:57:38

问题


I'm searching for a way to build a photoshop like drawing tool in ActionScript 3. Especially I want to build something like the brushes in photoshop. So that you can use different PNG's as a brush.

I tried it with saving a brush in photoshop as a transparent png, import it into my AS3 project and with a mouse move event, draw the png everytime you move the mouse into a bitmapdata object. But that doesn't look like photoshop. Here's a example, first the photoshop drawing, then the as3 drawing:

In photoshop it looks very smooth, but in as3 you have that ugly corners and color shifts. Does anyone know a solution?

thx, tux


回答1:


To be more specific: You should make a temporary bitmap each time a mouseDown is fired. On this the brushes will be drawn in black and white - this will produce smoother results for example when you make the drawn brush not full in alpha. Also - here you will have to use the "walking" technique, as said by grapefrukt.

Finally, once the mouseUp event is fired, you have to recolor the bitmap (for brush color), possibly add some filters if you want and draw it on the main bitmap.




回答2:


The answer is that Flash draws bitmapData with pre multiplied alpha transparency. Flash basically conserves memory by rounding the nearly transparent pixels to another value. It is imperceptible to the human eye, unless you stack the images on top of each other over and over. This results in rounding errors of color that look almost like a burnt edge of the brush.

You definitely need to "walk" the brush in between mouse positions as others have noted, but that wont take care of the color shifting that happens when you stack images on top of one another.

Instead draw your brush stroke into a transparent bitmap and tint that new layer to your selected color using the colorTransform method. When you mouse up, draw that transparent layer into your canvas. (Don't forget to remove that extra layer when you are not using it!)




回答3:


This is because Photshop "walks" the distance between the mouse coordinates and paints that too. So even if you're moving your mouse very fast between two points you will get a coherent line.

You're only drawing once per mouse update, so if the mouse is moving very fast you will get spots instead of lines.

You can solve this by keeping track of the position of the last mouse update, and if it's too far between paint in the extra steps.



来源:https://stackoverflow.com/questions/3616902/as3-photoshop-brushes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!