应该如何缩放叠加图像?

发布于 2024-11-12 06:12:27 字数 1333 浏览 3 评论 0原文

我有一个用于创建图像叠加的简单函数。

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)时就会出现问题。那么叠加标志无法正确显示! 如何正确缩放覆盖标志以适合所有分辨率?

I have a simple function for creating image overlay.

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;
}

My overlay image size is 72x72.

Problem comes when try to overlay very small image for example resolution 57x88. Then the overlay sign is not proper displayed!
How to proper scale the overlay sign to be adequate for all resolutions ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文