如何缩放叠加图像?

时间:2011-06-04 20:32:40

标签: android android-layout image-scaling

我有一个简单的功能来创建图像叠加。

public  String getMyPath(Application app, Context c) {
    String path = Environment.getExternalStorageDirectory() + "image.jpg";

    Bitmap bmap = BitmapFactory.decodeFile(photo);
        Bitmap mutableBitmap = bmap.copy(Bitmap.Config.ARGB_8888, true);


        Canvas canvas = new Canvas(mutableBitmap);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        canvas.drawPaint(paint);

        paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);


        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inDither = true;
        opt.inPreferredConfig = Bitmap.Config.ARGB_8888;

        Bitmap itemBitmapOrg = BitmapFactory.decodeResource(c.getResources(), R.drawable.star, opt);

            Matrix matrix = new Matrix();



            matrix.postTranslate(0, 0);
            canvas.drawBitmap(bmap, 0, 0, null);
            canvas.drawBitmap(itemBitmapOrg,matrix,paint);



        FileOutputStream out=null;
        try {
            out = new FileOutputStream(new File(path));
        } catch (FileNotFoundException e) {
        }

        mutableBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    }

    return path;
}

我的叠加图片尺寸是72x72。

当尝试覆盖非常小的图像时出现问题,例如分辨率为57x88。然后叠加标志显示不正确! 如何正确地缩放叠加符号以适合所有分辨率?

0 个答案:

没有答案