android - 如何裁剪只在透明区域显示的图像?

标签 android transparent crop

在图像中,您可以显示一个固定的框架。我想裁剪仅显示在框架透明区域的图像部分。那么如何找到框架的透明区域呢?以及如何只让后面的图像只显示在透明区域...?

enter image description here

最佳答案

这里只是我们在相对布局之间获取两个 ImageView 。第一帧(快照中的 ImageView 上方)是固定的,在按钮点击监听器上是我们在框架后面调整的第二张图像,这里有一个简单的逻辑。并不复杂。

但主要的是我们想要框架的透明区域。这里的框架不像上面的截图那样,但无论如何,比如脸或手等等,我预先声明所以裁剪它(框架透明部分)并将它放在另一个图像中。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/Button01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Browse gallery" >
</Button>
<ImageView
    android:id="@+id/ImageView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:layout_below="@+id/Button01"
     >
</ImageView>

<ImageView
    android:id="@+id/ImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/Button01"
    android:background="@drawable/frame" >
</ImageView>

关于android - 如何裁剪只在透明区域显示的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11131880/

相关文章:

android - 如何比较安卓版本

c# - 图像透明度与另一个向后 c#

Android 位图裁剪中心

android - 添加 Pickimage,使用 1 :4 & Replace drawab. 图像裁剪 - 如何?

Android 自动裁剪相机拍摄的图像

java - Double.parseDouble 丢失小数位

android - 从服务器加载图像

Android、ADB命令行工具获取ORientation

background - CoreGraphics:图像透明背景

在 Xlib 中点击透明窗口