简体   繁体   English

在画布上绘制位图

[英]Draw bitmap on canvas

I tried searching for a relevant example but found none, so I'll try to be as precise as I can. 我尝试搜索相关示例,但未找到任何示例,因此,我将尽可能精确。

Back in the gingerbread era I made a draw bitmap to canvas code that worked flawlessly and here it is. 回到姜饼时代,我在画布代码上绘制了一个绘图位图,该位图可以完美地工作了。

//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);

anyways the code doesn't seem to fit now. 无论如何,现在的代码似乎不合适。 One problem I have faced is converting the bitmap into mutable which you can check out here if you are stuck on it as I was for a while. 我遇到的一个问题是将位图转换为可变的,如果像我以前那样卡在位上,则可以在此处查看。

My problem is that the background is perfectly drawn but the mBackImage doesn't show up at all. 我的问题是背景画得很完美,但是mBackImage根本不显示。 What worries me more is that this used to work perfectly before. 更让我担心的是,此功能以前曾经非常完美。

I really have tried searching for a newer explanation but haven't really found any on stackoverflow so 我确实尝试过寻找较新的解释,但在stackoverflow上还没有真正找到任何解释,因此

I drew bitmap as background image for my app as well. 我也为我的应用程序绘制了位图作为背景图像。 I used: setBackgroundDrawable() instead of setBackground() in your last statement. 我在上一条语句中使用了:setBackgroundDrawable()而不是setBackground()。

Also, when preparing the bitmap, I set two options: 另外,在准备位图时,我设置了两个选项:

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

You can give it a try. 您可以尝试一下。

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

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