Android 画布只显示黑屏

Android 画布只显示黑屏,android,tiles,Android,Tiles,我试着将图像拼接成一张画布 这是我的密码 Canvas createCanvas(Bitmap[][] array){ int height = array[0][0].getHeight(); int width = array[0][0].getWidth(); Bitmap bitmap = Bitmap.createBitmap(3*height,3*width,Bitmap.Config.ARGB_8888); Canvas canvas = new

我试着将图像拼接成一张画布

这是我的密码

Canvas createCanvas(Bitmap[][] array){

    int height = array[0][0].getHeight();
    int width = array[0][0].getWidth();
    Bitmap bitmap = Bitmap.createBitmap(3*height,3*width,Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap (array[0][0],0f,0f,new Paint(Paint.ANTI_ALIAS_FLAG));
    canvas.drawBitmap (array[0][1],width,0f,new Paint(Paint.FILTER_BITMAP_FLAG));
    //etc..etc..for all the tiles

    return canvas;
}
按如下方式调用此方法:

    //source File
    Bitmap bMap = BitmapFactory.decodeResource(getResources(),R.drawable.image);
    //Tile Source File
    Bitmap [][] array_ref = helper_ref.createImageArrays(bMap);

    //Invoke Method above
    Canvas canvas = helper_ref.createCanvas(array_ref);
    //Draw canvas 
    ImageView view_ref = (ImageView) findViewById(R.id.imageView1);
    view_ref.draw(canvas);
我还提供了我要绘制的视图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />

看看最后一行中调用的“draw”方法的说明:

void draw(Canvas canvas)
    Manually render this view (and all of its children) to the given Canvas.
因此,它所做的唯一事情就是将ImageView(它是空的)绘制到画布上。因此,实际发生的事情与您想要实现的正好相反:您正在将ImageView绘制到位图中,而不是相反。
解决方案很简单:最后,您的方法
createCanvas
不应该返回画布上的位图,而是返回您正在绘制的位图。使用位图,执行以下操作:
view_ref.setBackgroundDrawable(新的BitmapDrawable(getResources(),位图))

这应该可以解决问题。

我认为问题在于canvas.drawBitmap中的最后一个参数传递null。试着通过一个绘画物体。嗯,它不起作用,但它是一个线索。我传入了一个默认对象new Paint()。可能是弄错了?我尝试了2个绘画常量,但没有成功,我想不是这样。我还提供了我绘制的视图。