在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图片的合成已经完成。如果大家有更好的方法,欢迎留言交流。
合成图片最重要的是对透明度的处理,以免图片合成错误
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图片的合成已经完成。如果大家有更好的方法,欢迎留言交流。
相关文章推荐
- 在Android中的大图片合成-PNG(一) PNG格式详解
- android-xBuild apk差分与合成,zip差分与合成,lua打包,apk打包,png/jpg图片压缩
- 在Android中的大图片合成-PNG(二) PNG解压
- android-xBuild apk差分与合成,zip差分与合成,lua打包,apk打包,png/jpg图片压缩
- Android实现多张图片合成GIF
- android 9PNG图片制作
- Android中加载PNG图片时出现错误----No resource found
- android开发 两张bitmap图片合成一张图片
- Android PNG图片像素检测及剪裁优化
- Android图片的合成
- Android apk瘦身之使用TinyPng压缩图片
- [Android] 给图像添加相框、圆形圆角显示图片、图像合成知识
- Android PNG透明渐变背景图片失真问题
- 『ANDROID』Android中使用到的四种类型的PNG图片
- Android Studio png图片 libpng error not a png file问题
- Android PNG渐变背景图片失真问题 getWindow().setFormat(PixelFormat.RGBA_8888);
- Android 关于.9图片the file is not a PNG
- 先将小图片合成大的PNG文件,生成xml索引文件,再用XML解析
- android 文字图片合成
- Android图片,PNG还是JPG?用哪种?