gpt4 book ai didi

安卓 : How to create a bitmap with exact physical size in inches

转载 作者:行者123 更新时间:2023-11-29 15:52:31 26 4
gpt4 key购买 nike

我需要在 android 中创建一个位图,并使用最终将使用照片打印机打印的 Canvas 在其上绘制一些东西。基本上我正在尝试创建实际 5x7 大小(5 英寸 X 7 英寸)的 jpg。因此,如果位图通过电子邮件发送或复制到计算机,它可以正确地放入 5X7 照片打印纸中。

在createbitmap方法中指定高和宽时,需要指定什么值才能使位图的实际大小为5x7。这取决于设备的屏幕密度等吗?

最佳答案

试试这个方法:

public void setViewInInches(float width, float height, View v) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int widthInches = Math.round(width * metrics.xdpi);
int heightInches = Math.round(height * metrics.ydpi);
v.setLayoutParams(new LinearLayout.LayoutParams(widthInches, heightInches));
v.requestLayout();
}

传入宽度和高度,然后是您要将其设置为的 View ,它应该可以工作。将 ImageView 设置为 5x7 的示例调用:

setViewInInches(5f, 7f, imageView);

关于安卓 : How to create a bitmap with exact physical size in inches,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29425468/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com