我怎么可以复制位图到另一个位图,而无需使用createBitmap()和复印件()在Android? [英] How can I copy bitmap to another bitmap without using createBitmap() and copy() on Android?

查看:351
本文介绍了我怎么可以复制位图到另一个位图,而无需使用createBitmap()和复印件()在Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个位图,我的onCreate()。

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

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

BMP1和BMP2相同。我修改BMP2在我的应用程序。经过我的任务完成了,我点击清除按钮。我试图复制BMP1(干净的形象)到BMP2(改变形象),当我点击清除按钮。但我不希望使用createBitmap()或复制()函数。因为这些都是创建新的位图对象。我只想用我的两个位图(BMP1和BMP2)。我怎样才能复制BMP1到BMP2?我搜索谷歌,但你感到沉沦这样与createBitmap()或复制()。

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().

感谢。

推荐答案

我解决我的问题。

首先,我创建了BMP1,BMP2和帆布BMP2:

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

当我想BMP1复制到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);
}

这篇关于我怎么可以复制位图到另一个位图,而无需使用createBitmap()和复印件()在Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆