Note that there are some explanatory texts on larger screens.

plurals
  1. POBitmap not drawn anti-aliased
    primarykey
    data
    text
    <p>I have a custom <code>View</code> that always draws a <code>Bitmap</code> at a certain rotation. I overwrite the <code>onDraw</code> method, rotate the <code>Canvas</code> and draw the bitmap with an anti-aliased <code>Paint</code>.</p> <pre><code>public RotatedImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); someBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder); } @Override protected void onDraw(Canvas canvas) { // Save and rotate canvas canvas.save(); canvas.rotate(3F, getWidth() / 2, getHeight()); // Draw the icon Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); canvas.drawBitmap(someBitmap, 0, 0, p); canvas.drawRoundRect(new RectF(75, 50, 225, 200), 10, 10, p); // All done; restore canvas canvas.restore(); } </code></pre> <p>However, I always get jagged edges on the Bitmap. Note that the roudned rectangle gets nicely anti-aliased edges. Also, when I apply <code>p.setFilterBitmap(true);</code> this works (the bitmap surface gets filtered/smoothed) correctly. Am I missing something?</p> <p><img src="https://i.stack.imgur.com/qFxl5.png" alt="No anti-aliasing on the photo"></p> <p>Here's a minimal Android project with isolated example of one screen that shows the View that draws the non-anti-aliased Bitmap, loaded from a resource: <a href="https://bitbucket.org/erickok/antialiastest" rel="noreferrer">https://bitbucket.org/erickok/antialiastest</a></p> <p><strong>UPDATE:</strong> I have also tried the following:</p> <pre><code> Paint p = new Paint(); p.setAntiAlias(true); p.setFilterBitmap(true); p.setDither(true); canvas.drawBitmap(someBitmap, 0, 0, p); </code></pre> <p>But this doesn't help as <code>setFilterBitmap</code> filters the surface; it does not anti-alias the edges. Also, <code>setAntiAlias</code> does the same as directly setting the flag in the <code>Paint</code> constructor. If in doubt, please try my minimal test project. Thanks so much for any help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload