LightBlog

dimanche 1 mars 2015

Embossing an image shape in android (using EmbossMaskFilter)

I want to get an embossed bitmap created based on a Path object. The problem is that embossed effect only applies for straight edge.

I want to get a final result like this. basic colors jigsaw pieces from cycreation, Royalty-free stock photo #1066946 on Fotolia.co.uk



How can I improve the following code.




Path Object is created as follows

Path mPath=newPath();

mPath.moveTo(100,100);

mPath.lineTo(200,100);

mPath.lineTo(150,150);

mPath.lineTo(200,200);

mPath.lineTo(100,200);

mPath.close();


Then a bitmap is created out of this path object as follows. With the embossed filter.



piecePicture =Bitmap.createBitmap(200,200,Bitmap.Config.ARGB_88 88);


MaskFilter mEmboss =newEmbossMaskFilter(newfloat[]{1,1,1},0.4f,6,3.5f);Canvas gfx =newCanvas(piecePicture);





Paint whitePaint =newPaint(Paint.ANTI_ALIAS_FLAG);

whitePaint.setColor(Color.WHITE);

whitePaint.setStyle(Paint.Style.FILL_AND_STROKE);

whitePaint.setStrokeWidth(1);



// shape image has to take

mPath.addRect(10,10,195,195,Direction.CCW);

gfx.drawPath(mPath, whitePaint);



Paint paint =newPaint();

paint.setXfermode(newPorterDuffXfermode( android.graphics.PorterDuff.Mode.SRC_IN));

paint.setMaskFilter(mEmboss);// draw the image on path viewBgrnd is the bitmap

gfx.drawBitmap(viewBgrnd,10,10, paint);




Thanks





from Android Forum http://ift.tt/1GEGLA4

via IFTTT

Aucun commentaire:

Enregistrer un commentaire