使用layout.getDrawingCache()根据视口裁剪图像

发布于 2024-12-12 18:44:49 字数 445 浏览 0 评论 0原文

我有一个绝对布局,其中包含 2 个按钮和一个动态添加的图像。图像的宽度和高度大于屏幕尺寸,并且可以双向滚动。我需要在此图像上放置动态文本。文本视图在运行时添加,并且可以拖动到图像中的任何位置。 将文本视图放置在所需位置后,我需要使用动态放置的文本存储图像。为此,我使用下面的代码

absView.setDrawingCacheEnabled (true);              
bitmap = Bitmap.createBitmap(absView.getDrawingCache());
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
absView.setDrawingCacheEnabled(false);

,但位图仅包含可见视图,而不包含大于屏幕尺寸的整个图像的隐藏视图。 如何使用动态放置的文本视图在位图中捕获整个布局视图?

I have a absolute layout which contain 2 buttons and a dynamically added image . Image width and height are larger than screen size and is scrollable in both directions . I need to place a dynamic text on this image . The text view is added at runtime and is drag-gable to anywhere in image .
After placing text view at required position i need to store image with the dynamically placed text. For this I am using below code

absView.setDrawingCacheEnabled (true);              
bitmap = Bitmap.createBitmap(absView.getDrawingCache());
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
absView.setDrawingCacheEnabled(false);

But the bitmap contains only the visible view not the hidden view of the whole image which is larger than screen-size.
How can I get whole layout view to be captured in bitmap with dynamically placed textview ?

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

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

发布评论

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

评论(2

倒带 2024-12-19 18:44:49

您将无法通过 absView.getDrawingCache() 获取视图的绘图缓存,
对于不可见的部分,不会存储缓存,我想

如果您想要合并位图,这可能会帮助您

在android中合并两个png文件

you wont be able to as absView.getDrawingCache() get you the drawing cache of the view,
for portions that are not visible, no cache wud be stored, i think

if you are looking to merge bitmaps this might help you

combining two png files in android

她如夕阳 2024-12-19 18:44:49

我不确定这是否有效,但值得一试

 Bitmap viewBitmap = Bitmap.createBitmap(viewWidth,viewHeight,Bitmapconfig);
 Canvas viewCanvas = new Canvas(viewBitmap);
 absView.draw(viewCanvas);

,此 viewBitmap 可能会将完整视图绘制到其中。

绘图缓存不会具有完整视图,因为仅绘制视图的可见部分,这就是缓存的内容。

Im not sure if this will work but worth a try

 Bitmap viewBitmap = Bitmap.createBitmap(viewWidth,viewHeight,Bitmapconfig);
 Canvas viewCanvas = new Canvas(viewBitmap);
 absView.draw(viewCanvas);

After this viewBitmap might have the full view drawn into it.

The drawingcache will not have the full view as only the visible portion of the view is drawn and that is what is cached.

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