繁体   English   中英

在画布上绘制位图

[英]Draw bitmap on canvas

我尝试搜索相关示例,但未找到任何示例,因此,我将尽可能精确。

回到姜饼时代,我在画布代码上绘制了一个绘图位图,该位图可以完美地工作了。

//this one is drawing the background for my picture
mBackground = BitmapFactory.decodeResource(getResources(), R.drawable.base);

//setting a new canvas
mComboImage = new Canvas(mBackground);

//adding another bitmap to the canvas, don't worry about the size or the i variables 
mBackImage = BitmapFactory.decodeResource(getResources(), R.drawable.base);
      mBackImage=Bitmap.createScaledBitmap(mBackImage, size, 105, false);
      mComboImage.drawBitmap(mBackImage, 100f+1f*size*i, 170f, null);
      mBackImage.recycle();

//this is setting my background for an icon to the completed image
Drawable d =new BitmapDrawable(getResources(),mBackground);
                aaa.setBackground(d);

无论如何,现在的代码似乎不合适。 我遇到的一个问题是将位图转换为可变的,如果像我以前那样卡在位上,则可以在此处查看。

我的问题是背景画得很完美,但是mBackImage根本不显示。 更让我担心的是,此功能以前曾经非常完美。

我确实尝试过寻找较新的解释,但在stackoverflow上还没有真正找到任何解释,因此

我也为我的应用程序绘制了位图作为背景图像。 我在上一条语句中使用了:setBackgroundDrawable()而不是setBackground()。

另外,在准备位图时,我设置了两个选项:

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inPurgeable = true;
options.inInputShareable=true;  
bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.image1), options);

您可以尝试一下。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM