【发布时间】:2016-12-29 23:49:04
【问题描述】:
我正在尝试将拍摄的照片位图很好地放入画布中进行绘画,但是画布总是忽略位图的大部分。
我正在使用CanvasView API from GitHub,它使用以下 XML 扩展视图
<com.android.graphics.CanvasView
android:id="@+id/canvasView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
当使用来自here 的另一个 GitHub API 代码中的位图时出现问题:
Bitmap bitmap = ImageLoader.init().from(photoPath).requestSize(width, height).getBitmap();
之后,我将使用上面的位图导入到画布中进行绘制:this.canvasView.drawBitmap(bitmap);
因此,在 .drawBitmap() API 中,它不是通常的 drawBitmap(bitmap,width,height,paint);
public void drawBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
this.invalidate();
}
尝试了这两种方法来尝试解决问题,但无济于事,还是我在探索错误的方向?还是我在两者之间错过了间歇性步骤/代码?感谢您提供的任何帮助!
canvasView.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);
width = canvasView.getMeasuredWidth();
height = canvasView.getMeasuredHeight();
和
canvasView.post( new Runnable() {
@Override
public void run() {
int width = canvasView.getMeasuredWidth();
int height = canvasView.getMeasuredHeight();
}
});
【问题讨论】:
-
位图尺寸是否按要求正确?