画布为ImageView/Bitmap

Ala*_*agh 2 java android

我无法理解我的这个问题.我有2个图像被添加到画布并将被视为一个对象,现在我需要将此画布作为位图/可绘制返回,因为这是代码我如何将2位图添加到画布

Bitmap image1=BitmapFactory.decodeResource(getResources() ,R.drawable.icon1);
Bitmap image2=BitmapFactory.decodeResource(getResources() R.drawable.icon2);
Rect srcRect = new Rect(0, 0, image.getWidth(), image.getHeight());
Rect dstRect = new Rect(srcRect);
dstRect.offset(15, 0);      
        canvas.drawBitmap(image, srcRect, dstRect, null);

        dstRect.offset(image.getWidth(), 0);    

        canvas.drawBitmap(image2, srcRect, dstRect, null);
       //return???????????
Run Code Online (Sandbox Code Playgroud)

请有人帮忙.Tnx提前!

Mar*_*los 5

您可以创建一个要绘制的位图.

Bitmap image1=BitmapFactory.decodeResource(getResources() ,R.drawable.icon1);
Bitmap image2=BitmapFactory.decodeResource(getResources() R.drawable.icon2);
Bitmap result = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);//Create the canvas to your image
Rect srcRect = new Rect(0, 0, image.getWidth(), image.getHeight());
Rect dstRect = new Rect(srcRect);
dstRect.offset(15, 0);      
canvas.drawBitmap(image, srcRect, dstRect, null); //draw on it
dstRect.offset(image.getWidth(), 0);    
canvas.drawBitmap(image2, srcRect, dstRect, null);
return result;//result will have the drawed images from the canvas
Run Code Online (Sandbox Code Playgroud)