Thursday, March 27, 2014

drawing canvas by matrix problem


1, a custom mView extended ImageView, rewrite his ondraw function

The original drawable resource decode into a bitmap, reduced to 0.667

Then draw directly canvas.drawbitmap out, the effect is very poor, brush set paint.setAntiAlias ​​(true);

But if he was drawn on a ARGB_8888 the bitmap, then draw the bitmap, with good results

Seeking to explain


2, or at the mView

Put a 112px (width, whichever) around the image, zoom in to about 130px, then rotate
15 degrees
Draw directly canvas.drawbitmap out, the effect of extremely poor

Brush set paint.setAntiAlias ​​(true);

Seek solutions
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
drawbitmap time settings Paint the setDither try
Paint p = new Paint ();
p.setDither (true);


Paste the mView class look

Reply:
cited a floor fontlose reply: Paint the setDither settings when you try
drawbitmapPaint p = new Paint ();
p.setDither (true);


Paste the mView class look


Set setDither useless, to say the least effect did not significantly improve

The following is the code:
 public class RotateView extends ImageView {

Paint mPaint;
Bitmap userBmp;
Matrix matrix;


public RotateView (Context context, AttributeSet attrs) {
super (context, attrs);
/ / TODO Auto-generated constructor stub
mPaint = new Paint ();
mPaint.setAntiAlias ​​(true);
mPaint.setFlags (Paint.ANTI_ALIAS_FLAG);
mPaint.setDither (true);
}
@ Override
public void setImageBitmap (Bitmap bmp) {
/ / TODO Auto-generated method stub
userBmp = bmp;
invalidate ();
}
@ Override
protected void onDraw (Canvas canvas) {
if (userBmp! = null)
{
matrix = new Matrix ();
float xScale = 75f/userBmp.getWidth ();
float yScale = 75f/userBmp.getHeight ();

if (userBmp.getHeight () {
matrix.postScale (xScale, yScale);
}
else
{
matrix.postScale (xScale, xScale);
}
matrix.postScale (1.75f, 1.75f);
matrix.postRotate (15);
matrix.postTranslate (50, 4);
canvas.drawBitmap (userBmp, matrix, mPaint);
matrix = null;
}
}
}

Reply:
The next test you did not see what the problem is with setImageBitmap passed in Bitmap object has no problem with how the resulting Bitmap?
Reply:
reference to the third floor fontlose reply:
next test you did not see what the problem is with setImageBitmap passed in Bitmap object has no problem with how the resulting Bitmap?



Read back from the server
Size of the figure is probably around 112, the size of the scaled probably around 130

Magnified a little bit, but this effect is poor too outrageous
Reply:
Do not you add so many effects,
matrix.postScale (1.75f, 1.75f);
matrix.postRotate (15);
matrix.postTranslate (50, 4);
The effect will not be too bad to try individually or without effects look bad, then it is not a question of
code
Reply:
There is a way that you will look to your canvas also set anti-aliasing, code:
canvas.setDrawFilter (new PaintFlagsDrawFilter (0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
Reply:
MARK, the word seems too little,

No comments:

Post a Comment