我正在尝试在我的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“到我的画布上。在这里,我只希望在画布上渲染图像的一部分。
我尝试使用方法:"setRectToRect() on Matrix","canvas.drawBitmap(bitmap,src,dst,paint)“。但是,并没有得到适当的结果。
使用SurfaceViews会有帮助吗?有没有人遇到过这种情况?请发表你的想法/想法。
发布于 2011-12-16 05:17:00
为什么不直接使用下面的代码呢?
Canvas.drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)src对应于您要绘制的位图区域,而dst表示您希望绘制位图的位置。你可以在这里阅读更多信息:http://developer.android.com/reference/android/graphics/Canvas.html
发布于 2011-12-17 00:56:01
当我这样做时,我得到的是一个较小的位图图像,而不是裁剪后的图像。以下是我使用的代码片段。
Canvas c = holder.lockCanvas();
c.drawRGB(10, 10, 10);
Rect src = new Rect((int)x - _image.getWidth(), (int) y - _image.getHeight(), (int)x + _image.getWidth(), (int) y + _image.getHeight());
RectF dst = new RectF((int)x - 50, (int) y - 50, (int)x + 50, (int) y + 50);
c.drawBitmap(_image, src, dst, null);
holder.unlockCanvasAndPost(c);https://stackoverflow.com/questions/8526513
复制相似问题