首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >创建一个新的位图并绘制新的像素。

创建一个新的位图并绘制新的像素。
EN

Stack Overflow用户
提问于 2012-04-16 19:33:59
回答 2查看 39.3K关注 0票数 8

我正在尝试制作一个应用程序,它将拍摄两张您通过editText指定的图片,比较两个图像上每个像素的颜色,并创建一个新的图片(位图)(您可以保存到sd卡),其中包含两个原始图片之间的差异。

我在创建这个新位图时遇到了问题。我怎样才能达到我的目标?我真的不知道该如何做,我是先创建新的位图,然后写入其中,还是先得到差异,然后再从中绘制位图?这些照片将接近。300 x 300 px

EN

Stack Overflow用户

发布于 2012-04-16 20:01:36

我会首先创建位图并计算每个像素之间的差异,但我们欢迎您先计算差异,然后使用Bitmap.copyPixels,但我认为第一种方法更容易理解。下面是一个示例:

代码语言:javascript
运行
复制
// Load the two bitmaps
Bitmap input1 = BitmapFactory.decodeFile(/*first input filename*/);
Bitmap input2 = BitmapFactory.decodeFile(/*second input filename*/);
// Create a new bitmap. Note you'll need to handle the case when the two input
// bitmaps are not the same size. For this example I'm assuming both are the 
// same size
Bitmap differenceBitmap = Bitmap.createBitmap(input1.getWidth(), 
    input1.getHeight(), Bitmap.Config.ARGB_8888);
// Iterate through each pixel in the difference bitmap
for(int x = 0; x < /*bitmap width*/; x++)
{
    for(int y = 0; y < /*bitmap height*/; y++)
    {
        int color1 = input1.getPixel(x, y);
        int color2 = input2.getPixel(x, y);
        int difference = // Compute the difference between pixels here
        // Set the color of the pixel in the difference bitmap
        differenceBitmap.setPixel(x, y, difference);
    }
}
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10180449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档