android 复制bitmap_我怎么可以复制位图到另一个位图,而无需使用createBitmap()和复印件()在Android?...

I have two bitmaps and I create them in onCreate().

Bitmap bmp1 = BitmapFactory.decodeResource(getResources(),id);

Bitmap bmp2 = BitmapFactory.decodeResource(getResources(),id);

bmp1 and bmp2 are same. I modify bmp2 in my application. After my job is done, I click "Clear" button. I am trying to copy bmp1 (clean image) to bmp2(changed image) when I click "Clear" button. But I don't want to use createBitmap() or copy() function. Because these are create new Bitmap objects. I want to use only my two bitmaps (bmp1 and bmp2). How can I copy bmp1 to bmp2? I search google but everbody do this with createBitmap() or copy().

Thanks.

解决方案

I solved my problem

First I created bmp1,bmp2 and canvas for bmp2:

bmp1 = BitmapFactory.decodeResource(cont.getResources(), R.drawable.image);

bmp2 = bmp1.copy(bmp1.getConfig(), true);

canvasBmp2 = new Canvas( bmp2 );

When I want to copy bmp1 to bmp2:

canvasBmp2.drawBitmap(bmp1, 0, 0, null);

@Override

protected void onDraw(Canvas canvas)

{

canvas.drawBitmap(bmp2, 0, 0, null);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值