Optimizing Custom Crop Drawing
I've implemented drawing for component like in picture following way: @Override protected void onDraw(Canvas canvas) { int w = canvas.getWidth(); int h = canvas.getHeight()
Solution 1:
Following drawing can be achieved using BitmapShader
with the image to be drawn, then I only need to create ALPHA_8 Bitmap
to draw with Paint
object using the shader. However shaders are pinned into window coordinates, so using this method inside scrolling components can cause some problems because the Matrix
needs to be translated properly.
// Create bitmap shader
if (mShaderBitmap == null) {
mShaderBitmap = use wanted bitmap here.
BitmapShader shader = new BitmapShader(mShaderBitmap,
TileMode.CLAMP, TileMode.CLAMP);
mPaint.setShader(shader);
}
// Create alpha bitmap to draw with shader paint
if (mBitmapToDraw == null) {
mBitmapToDraw = load the shape here with ALPHA_8 Config
}
canvas.drawBitmap(mBitmapToDraw, 0, 0, mPaint);
Post a Comment for "Optimizing Custom Crop Drawing"