您的位置:首页 > 移动开发 > Android开发

在Android中的大图片合成-PNG(三) PNG合成

2013-08-28 09:49 232 查看
在图片合成上,我们需要合成N张PNG图片,合成时需要注意叠加的图片任就需要进行解压缩处理,保留IDAT数据即可。一行一行的读取,一行一行的操作,而且需要备份好原来合成前的行

合成图片最重要的是对透明度的处理,以免图片合成错误

for (AddFile addFile : addFileList) {
if(currentLine >= addFile.positionY && currentLine < (addFile.positionY + addFile.imgHeigth)){
for (int j = 0; j < addFile.imgWidth; j++) {
if(addFile.colorPixel == 4){
int pos1 = 1 + (j + addFile.positionX)*imgPixel;
if(pos1 < 0 || (imgPixel == 3 && pos1+2 >= InflaterArray.length) || (imgPixel == 4 && pos1+3 >= InflaterArray.length)){break;}
int pos2 = (currentLine - addFile.positionY) * (addFile.imgWidth * addFile.colorPixel + 1) + j * addFile.colorPixel + 1;
int alpha1 = 0xFF;
if (imgPixel == 4)
alpha1 = b2i(InflaterArray[pos1 + 3]);
int alpha2 = b2i(addFile.data[pos2 + 3]);
int alpha3 = sature(alpha1, alpha2);

InflaterArray[pos1] = (byte)sature(b2i(InflaterArray[pos1]) * (255 - alpha2) / 255, b2i(addFile.data[pos2]) * alpha2 / 255);
++pos1; ++pos2;
InflaterArray[pos1] = (byte)sature(b2i(InflaterArray[pos1]) * (255 - alpha2) / 255, b2i(addFile.data[pos2]) * alpha2 / 255);
++pos1; ++pos2;
InflaterArray[pos1] = (byte)sature(b2i(InflaterArray[pos1]) * (255 - alpha2) / 255, b2i(addFile.data[pos2]) * alpha2 / 255);
++pos1; ++pos2;
if (imgPixel == 4) InflaterArray[pos1] = (byte)alpha3;
}
}
}
}

至此PNG图片的合成已经完成。如果大家有更好的方法,欢迎留言交流。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: