使用layout.getDrawingCache()根据视口裁剪图像
我有一个绝对布局,其中包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将无法通过
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
我不确定这是否有效,但值得一试
,此 viewBitmap 可能会将完整视图绘制到其中。
绘图缓存不会具有完整视图,因为仅绘制视图的可见部分,这就是缓存的内容。
Im not sure if this will work but worth a try
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.