2015-01-09 3 views
0

Я разрабатываю приложение цветной всплеск. в котором я использую краску для пальцев.Эмбосс растровое изображение при касании в android

Теперь я хочу тиснить растровое изображение при касании. У меня есть одна демонстрация здесь, в которой, когда я применяю тиснение, тогда он рисует путь с тиснением с красным цветом, но я хочу выбить за растровое изображение при касании.

private Path mPath; 
private MaskFilter mEmboss; 

public void init(){ 
    mPaint = new Paint(); 
    mPaint.setAntiAlias(true); 
    mPaint.setDither(true); 
    mPaint.setColor(color.RED); 
    mPaint.setStyle(Paint.Style.STROKE); 
    mPaint.setStrokeJoin(Paint.Join.ROUND); 
    mPaint.setStrokeCap(Paint.Cap.ROUND); 
    mPaint.setStrokeWidth(20); 
    mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f); 
} 



// on click event 
    switch (item.getItemId()) { 
     case EMBOSS_MENU_ID:       
      mPaint.setMaskFilter(mEmboss); 
    } 



// View Class method 

@Override 
public void onDraw(Canvas canvas) { 
    super.onDraw(canvas);   
    canvas.drawPath(mPath, mPaint); 
    canvas.drawPath(circlePath, circlePaint); 
} 

@Override 
public boolean onTouchEvent(MotionEvent ev) { 
    float x = ev.getX(); 
    float y = ev.getY(); 
    invalidate(); 
    return true; 
} 

ответ

2

я в конечном счете найти решение:

Использование BitmapShader с таким же битовой карты

private Path mPath; 
private MaskFilter mEmboss; 

public void init(){ 
    mPaint = new Paint(); 
    mPaint.setAntiAlias(true); 
    mPaint.setDither(true); 
    mPaint.setColor(color.RED); 
    mPaint.setStyle(Paint.Style.STROKE); 
    mPaint.setStrokeJoin(Paint.Join.ROUND); 
    mPaint.setStrokeCap(Paint.Cap.ROUND); 
    mPaint.setStrokeWidth(20); 
BitmapShader fillBMPshader = new BitmapShader(bm_original, Shader.TileMode.MIRROR, Shader.TileMode.CLAMP); 
mPaint.setShader(fillBMPshader); 
    mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f); 
}  

// onclick event 
    switch (item.getItemId()) { 
     case EMBOSS_MENU_ID:       
      mPaint.setMaskFilter(mEmboss); 
    } 

// View Class method 

@Override 
public void onDraw(Canvas canvas) { 
    super.onDraw(canvas);   
    canvas.drawPath(mPath, mPaint); 
    canvas.drawPath(circlePath, circlePaint); 
} 

@Override 
public boolean onTouchEvent(MotionEvent ev) { 
    float x = ev.getX(); 
    float y = ev.getY(); 
    invalidate(); 
    return true; 
} 
Смежные вопросы