在 Android 中的画布上显示位图图像的一部分
我正在尝试在我的 Android 应用程序中构建一个放大工具。为此,我有一个 ImageView,我将其转换为位图(具有一些缩放/比例因子)。
imageView.setDrawingCacheEnabled(true);
Bitmap drawingCache = imageView.getDrawingCache(true);
Matrix matrix = new Matrix();
matrix.postScale(5, 5);
Bitmap viewCapture = Bitmap.createBitmap(drawingCache, 0, 0,
drawingCache.getWidth(),
drawingCache.getHeight(),
matrix, true);
imageView.setDrawingCacheEnabled(false);
现在,我正在将此位图图像“viewCapture”绘制到我的画布上。在这里,我只想在画布上渲染图像的一部分。
我尝试使用方法:“Matrix 上的 setRectToRect()”、“canvas.drawBitmap(bitmap、src、dst、paint)”。但是,没有得到适当的解决。
使用 SurfaceViews 有帮助吗?有人遇到过这种情况吗?请发表您的想法/想法。
I am trying to build a Magnify tool in my Android app. For this, I have an ImageView, which I converted to Bitmap (with some zoom/scale factor).
imageView.setDrawingCacheEnabled(true);
Bitmap drawingCache = imageView.getDrawingCache(true);
Matrix matrix = new Matrix();
matrix.postScale(5, 5);
Bitmap viewCapture = Bitmap.createBitmap(drawingCache, 0, 0,
drawingCache.getWidth(),
drawingCache.getHeight(),
matrix, true);
imageView.setDrawingCacheEnabled(false);
Now, I am drawing this Bitmap image "viewCapture" to my canvas. Here, I want only portion of the image to be rendered on the canvas.
I tried using approaches: "setRectToRect() on Matrix", "canvas.drawBitmap(bitmap, src, dst, paint)". But, didn't work out appropriately.
Would using SurfaceViews be helpful? Has anyone come across this situation? Please post your thoughts/ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不直接使用以下内容呢?
src
对应于您想要绘制位图的区域,dst
表示您想要绘制位图的位置。您可以在这里阅读更多相关信息: http://developer.android.com/reference /android/graphics/Canvas.htmlWhy not just use the following?
src
corresponds to which region of the bitmap you want to draw anddst
says where you want the bitmap drawn. You can read more about it here: http://developer.android.com/reference/android/graphics/Canvas.html当我这样做时,我会得到一个较小的位图图像,而不是裁剪后的图像。以下是我使用过的片段。
When I do that, I get a smaller image of the bitmap, instead of cropped image. Following is the snippet I have used.