结合在机器人2 PNG文件 [英] combining two png files in android

查看:88
本文介绍了结合在机器人2 PNG文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个PNG图像文件,我想我的Andr​​oid应用程序编程组合成一个PNG图像文件,并想知道是否有可能这样做?如果是的话,我愿意做的就是包裹在彼此创建一个文件。

I have two png image files that I would like my android app to combine programmatically into one png image file and am wondering if it is possible to do so? if so, what I would like to do is just overlay them on each other to create one file.

这背后的想法是,我有一个极少数的PNG文件,一些与图像的左侧,其余透明和与其他人的权利和休息的透明图像的部分。及根据用户的输入,将两者结合起来,以使一个文件以显示。 (和我不能只显示两个图像并列,他们需要的是一个文件)

the idea behind this is that I have a handful of png files, some with a portion of the image on the left with the rest transparent and the others with an image on the right and the rest transparent. and based on user input it will combine the two to make one file to display. (and i cant just display the two images side by side, they need to be one file)

这是可以做到的编程方式在Android和怎么做的?

is this possible to do programmatically in android and how so?

推荐答案

我一直在试图找出了这一点一会儿吧。

I've been trying to figure this out for a little while now.

下面的(本质)的code我用来做它的工作。

Here's (essentially) the code I used to make it work.

// Get your images from their files
Bitmap bottomImage = BitmapFactory.decodeFile("myFirstPNG.png");
Bitmap topImage = BitmapFactory.decodeFile("myOtherPNG.png");

// As described by Steve Pomeroy in a previous comment, 
// use the canvas to combine them.
// Start with the first in the constructor..
Canvas comboImage = new Canvas(bottomImage);
// Then draw the second on top of that
comboImage.drawBitmap(topImage, 0f, 0f, null);

// bottomImage is now a composite of the two. 

// To write the file out to the SDCard:
OutputStream os = null;
try {
    os = new FileOutputStream("/sdcard/DCIM/Camera/" + "myNewFileName.png");
    image.compress(CompressFormat.PNG, 50, os)
} catch(IOException e) {
    e.printStackTrace();
}

编辑:

有一个错字, 所以,我已经改变了

there was a typo, So, I've changed

image.com preSS(比较pressFormat.PNG,50,OS)

bottomImage.com preSS(比较pressFormat.PNG,50,OS)

这篇关于结合在机器人2 PNG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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