帆布只显示黑屏
问题描述:
我尝试concatenize图像块为一个帆布帆布只显示黑屏
这里是我的代码
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"
/>
答
看一看什么Google docs说的方法“画”你在最后一行调用:
void draw(Canvas canvas)
Manually render this view (and all of its children) to the given Canvas.
所以这样做的唯一事情就是绘制ImageView的(这是空的)到那个画布。因此,实际发生的事情与您想实现的目的相反:您将ImageView绘制到该位图中,而不是相反。
解决方案很简单:最后,您的方法createCanvas
不应返回画布,而应返回您正在绘制的位图。随着位图,这样做:view_ref.setBackgroundDrawable(new BitmapDrawable(getResources(), bitmap));
这应该做的伎俩。
我认为问题在于你为canvas.drawBitmap中的最后一个参数传递null。尝试传递一个绘画对象。 – m1ntf4n 2012-02-22 16:39:58
嗯它没有工作,但它是一个线索。我传入了一个默认的Object new Paint()。也许是错的? – dan 2012-02-22 16:45:05
我尝试了2个Paint Constants没有成功,我认为不是这样。我也为你提供我画的视图。 – dan 2012-02-22 16:50:29