Android - 将 ImageView 保存到具有全分辨率图像的文件

发布于 2024-12-22 18:56:46 字数 191 浏览 0 评论 0原文

我将图像放入 ImageView 中,并实现了多点触控来调整 ImageView 中的图像大小和移动图像。现在我需要将调整大小的图像保存到图像文件中。我已经尝试过 .getDrawingCache() 但该图像具有 ImageView 的大小。我希望图像显示 ImageView 显示的内容,但具有全分辨率(大于 ImageView)。

有什么想法吗?

I put an image inside an ImageView and have multitouch implemented to resize and move the image inside the ImageView. Now I need to save the resized image to a image file. I have tried the .getDrawingCache() but that image have the size of the ImageView. I want the image to show what the ImageView shows but with full resolution (larger than the ImageView).

Any ideas?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅听莫相离 2024-12-29 18:56:46

您可以在后台保存一个位图对象,您可以使用这段代码调整其大小:

Matrix matrix = new Matrix();
matrix.postScale(scaledWidth, scaledHeight);

Bitmap resizedBitmap = Bitmap.createBitmap(originalBitmap, 0, 0,
    originalBitmap.width(), originalBitmap.height(), matrix, true); 

并稍后使用以下代码保存它:

OutputStream fOut = null;
File file = new File(strDirectoy,imgname);
fOut = new FileOutputStream(file);

resizedBitmap.compress(Bitmap.CompressFormat.PNG, 0, fOut);
fOut.flush();
fOut.close();

You could hold a Bitmap Object in Background, which you can resize with this piece of code:

Matrix matrix = new Matrix();
matrix.postScale(scaledWidth, scaledHeight);

Bitmap resizedBitmap = Bitmap.createBitmap(originalBitmap, 0, 0,
    originalBitmap.width(), originalBitmap.height(), matrix, true); 

And save it later using this code:

OutputStream fOut = null;
File file = new File(strDirectoy,imgname);
fOut = new FileOutputStream(file);

resizedBitmap.compress(Bitmap.CompressFormat.PNG, 0, fOut);
fOut.flush();
fOut.close();
黑白记忆 2024-12-29 18:56:46

我的解决方案是使用用于 ImageView 的矩阵来获取翻译,并且我还有该图像的比例。使用这两个我裁剪了原始图像。

Bitmap resizedBitmap = Bitmap.createBitmap(
                        BitmapFrontCover, (int) UpperLeftCornerX,
                        (int) UpperLeftCornerY, (int) CropWidth,
                        (int) CropHeight);

My solution was to use the matrix that I used for the ImageView to get the translation and I also had the scale of that image. Using those two I cropped the original image.

Bitmap resizedBitmap = Bitmap.createBitmap(
                        BitmapFrontCover, (int) UpperLeftCornerX,
                        (int) UpperLeftCornerY, (int) CropWidth,
                        (int) CropHeight);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文