Comments (3)
这个头条换颜色,其实就是给原来的头发,上一层颜色而已,那么第一就需要有头发的精准区域。然后就可以参考画粉底或者口红的算法LipDraw,画上一层颜色即可。
参考部分代码如下,(不包含识别代码)
public class HairColorDraw {
public static void draw(Canvas canvas, Path hairPath, int color, int alpha, List<MakeupHairColorAdjustUtils.PathEntity> list) {
if (hairPath == null) return;
if (color == -1) return;
alpha = (int) (alpha * 0.8f + 0.5f);
//Bitmap mask = createMask(new Path(hairPath), color, position, alpha, 8);
drawAdjustHairColor(canvas, new Path(hairPath), color, alpha, list);
}
private static void drawAdjustHairColor(Canvas canvas, Path hairPath,int color, int alpha, List<MakeupHairColorAdjustUtils.PathEntity> list) {
Paint paint = new Paint();
canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(),alpha , Canvas.ALL_SAVE_FLAG);
paint.setStyle(Paint.Style.FILL);
paint.setMaskFilter(new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL));
paint.setColor(color);
canvas.drawPath(hairPath,paint);
if (list == null || list.isEmpty()) {
canvas.restore();
return;
}
paint.setColor(color);
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
paint.setDither(true);
paint.setFilterBitmap(true);
paint.setStrokeWidth(15);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
for (MakeupHairColorAdjustUtils.PathEntity pathEntity : list) {
paint.setStrokeWidth(pathEntity.paintSize);
if(pathEntity.isEraserPath){
paint.setColor(Color.TRANSPARENT);
paint.setMaskFilter(null);
}else{
paint.setColor(color);
paint.setMaskFilter(new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL));
}
paint.setXfermode(pathEntity.isEraserPath ? new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)
: new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
canvas.drawPath(pathEntity.path,paint);
}
canvas.restore();
}
private static Bitmap createMask(final Path path, int color, @Nullable PointF position, int alpha, int blur_radius) {
if (path == null || path.isEmpty())
return null;
RectF bounds = new RectF();
path.computeBounds(bounds, true);
int width = (int) bounds.width();
int height = (int) bounds.height();
if (width == 0 || height == 0) return null;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); // mutable
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.TRANSPARENT);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setMaskFilter(new BlurMaskFilter(blur_radius, BlurMaskFilter.Blur.NORMAL));
paint.setColor(color);
paint.setAlpha(alpha);
paint.setStyle(Paint.Style.FILL);
path.offset(-bounds.left, -bounds.top);
canvas.drawPath(path, paint);
if (position != null) {
position.x = bounds.left;
position.y = bounds.top;
}
return bitmap;
}
}
from makeup.
thanks for your reply but my problem is how can we find the "precise area of hair"
i found another code
https://github.com/crownyoung0303/Hairstyle-Simulation
however it uses NDK , can you please include this in your project with pre build ".SO" files
can you please help with this
thanks
from makeup.
本Project 仅仅是Demo,不是实际可使用的Project。 目前暂时没时间,考虑去做这么一个功能。
推荐的方式,你识别到目标区域,上颜色就OK。识别区域暂时也不是我研究的范围,所以很抱歉!暂时不会提供支持。
from makeup.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from makeup.