如何在Android上合并图片?

huangapple go评论153阅读模式
英文:

How can I merge pictures Android?

问题

我有2张图片,一张是背景,另一张是完整的图片。

我想要将它们合成一张图片,就像一张在另一张上面,然后将它们保存在您的手机上作为一张图片。

我应该学习和研究哪个JAVA库?

如果您能指导我使用在Android Studio开发的同一库,我将不胜感激。

英文:

I have 2 pictures, one is a background and the other is a complete picture.

I want to create one image from both of them as if one is above the other and save them on your cell phone as one image

Which JAVA library should I study and research?

I would be happy if you would refer me to the same library I develop in Android Studio.

答案1

得分: 0

是的,你可以这样做:

文件夹 drawable -> 新建 -> drawable 资源文件 -> 选择文件名并点击确定

然后你会得到以下内容:

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
       
</selector>

selector 标签内部,放置 layer-list 标签(记得闭合标签),在 layer-list 标签内部,放置 item 标签。

例如,你的结果可以是这样的:

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item>
            </item>
            <item>
            </item>
        </layer-list>
    </item>
</selector>

现在你可以自定义这两个项目。如果你想要在项目中放置图像,你可以像这样编写代码:

<item
    android:gravity="center_vertical|center_horizontal"
    android:drawable="@drawable/YOUR_IMAGE"
    android:width="96dp"
    android:height="96dp"
    tools:ignore="UnusedAttribute" />

如果你想要放置一个对象的形状,比如一个矩形,你可以像这样编写代码:

<item>
    <shape
        android:shape="rectangle">
        <solid
            android:color="#000000" />
        <size
            android:width="1080px"
            android:height="1920px" />
        <padding
            android:left="0dp"
            android:top="0dp"
            android:right="0dp"
            android:bottom="0dp" />
    </shape>
</item>

现在你的图像由两个图像(或其他内容)组成,如果你想要使用它,你只需要在你的 layout_activity.xml 文件中调用 android:background="@drawable/YOUR_FILE_NAME"

有了这些信息,我认为你可以解决你的问题,再见 如何在Android上合并图片?

英文:

Yes you can, this is what you have to do:

Folder drawable -> new -> drawable resource file -> choose the name of the file and click ok

and this is what you get

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;selector
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
    
   

&lt;/selector&gt;

Inside the tags selector put the tag &lt;layer-list&gt; (remember to close the tag) and inside the layer-list put the tag &lt;item&gt;

your result can be this for example:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;selector
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
        &lt;item&gt;
        &lt;layer-list&gt;
            &lt;item&gt;
            &lt;/item&gt;
            &lt;item&gt;
            &lt;/item&gt;
        &lt;/layer-list&gt;
        &lt;/item&gt;
&lt;/selector&gt;

Now you can customize your 2 items, if you want to put an image inside your item you can write your code like this:

&lt;item
    android:gravity=&quot;center_vertical|center_horizontal&quot;
    android:drawable=&quot;@drawable/YOUR_IMAGE&quot;
    android:width=&quot;96dp&quot;
    android:height=&quot;96dp&quot;
    tools:ignore=&quot;UnusedAttribute&quot; /&gt;

if you want to put a shape of an object like a rectangle you can write your code like this:

&lt;item&gt;
    &lt;shape
        android:shape=&quot;rectangle&quot;&gt;
        &lt;solid
            android:color=&quot;#000000&quot; /&gt;
        &lt;size
            android:width=&quot;1080px&quot;
            android:height=&quot;1920px&quot; /&gt;
        &lt;padding
            android:left=&quot;0dp&quot;
            android:top=&quot;0dp&quot;
            android:right=&quot;0dp&quot;
            android:bottom=&quot;0dp&quot; /&gt;
    &lt;/shape&gt;
&lt;/item&gt;

Now you have your image composed with 2 images (or other things) and if you want to use it you can just call android:background=&quot;@drawable/YOUR_FILE_NAME&quot; inside your layout_activity.xml for example

with this informations I think you can solve your problem, cya 如何在Android上合并图片?

huangapple
  • 本文由 发表于 2020年8月20日 22:06:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63506884.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定