用于缩放的android画布图形的图像分辨率

时间:2015-04-08 10:22:45

标签: android canvas

在我的Android应用程序中,我从Url下载图像,然后在画布上绘制之前按比例缩放到屏幕大小,如下所示。这个画布可以缩小到1.5倍。

1)假设我支持手机和平板电脑,这些图像的最佳分辨率是多少。

 InputStream is = conn.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(is);
    bm = BitmapFactory.decodeStream(bis);
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(bm,
                                    (int) width, (int) height, true);
    //width height are 0.75 of screen width height
    bm.recycle();
    bm = scaledBitmap;

2)然后,我使用路径对象将图像分割成10个部分,如下所示,并勾画图像。在未照相和缩放的图像中,轮廓并不那么明显。如何提高线条的平滑度和质量。

Bitmap piecePicture = Bitmap.createBitmap(100, 100,Bitmap.Config.ARGB_8888);

Canvas gfx = new Canvas(piecePicture);
// Canvas gfx = new Canvas(bm);
Paint whitePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
whitePaint.setColor(Color.WHITE);
whitePaint.setStyle(Paint.Style.FILL_AND_STROKE);
whitePaint.setStrokeWidth(1);

                           //translatedFigure is the path object
gfx.drawPath(translatedFigure, whitePaint);

Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(
android.graphics.PorterDuff.Mode.SRC_IN));

gfx.drawBitmap(sourcePicture, 0,
0, paint);

Paint mPaint = new Paint(Color.RED);
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);

EmbossMaskFilter mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
//new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
BitmapShader fillBMPshader = new BitmapShader(piecePicture, TileMode.MIRROR, TileMode.CLAMP);
 mPaint.setShader(fillBMPshader);
                mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 },0.4f, 6, 3.5f);

mPaint.setMaskFilter(mEmboss);

gfx.drawBitmap(piecePicture, 0,0, mPaint );


  //outline pen      
Paint outlinePen = new Paint(Color.BLACK);
outlinePen.setStyle(Paint.Style.STROKE);
outlinePen
.setStrokeWidth(1);
outlinePen.setAntiAlias(true);

gfx.drawPath(translatedFigure, outlinePen);

1 个答案:

答案 0 :(得分:0)

在画布上绘制位图之前设置这些标志。

paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);