【问题标题】:Android (eclipse) PNG transparency shown as black (with pic examples)Android(eclipse)PNG透明度显示为黑色(带有图片示例)
【发布时间】:2013-01-03 06:21:52
【问题描述】:

我在使透明 PNG 在 android/eclipse 中看起来透明时遇到问题。

我有这个:

<ImageView
        android:id="@+id/someid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/theimage" />

在图像视图中使用此图像时,XML 图形布局将图像透明度显示为黑色:

http://s7.directupload.net/file/d/3140/ehqd3yhm_png.htm

如果我使用以下图像,则透明度显示良好:

http://s7.directupload.net/file/d/3140/dc5aco6n_png.htm

您将在 Windows 桌面墙纸的前面看到透明的图像图标。您也可以手动验证图像,看看它们实际上都是透明的。

这是一个错误还是发生了什么?我无法创建将在 eclipse/android 中显示的透明 PNG。所以我从网上截了第二张图给大家看……

编辑:我需要使很多图像透明,目前我正在使用 irfanview。还有什么适合的程序?

EDIT2:

还有一点需要注意的是我放了

android:theme="@android:style/Theme.Light"

进入我的清单,因为我想要白色主题而不是黑色。不知道这是否有任何影响。

整个XML文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/beleg_imagegesperrt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:src="@drawable/ic_schloss_zu"/>

    <!-- this is the imageview I test with, i added  android:background="#FF0000" but does not help -->
    <ImageView
        android:id="@+id/beleg_imageabgeschlossen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClickBarauslagen"
        android:src="@drawable/dddd" 
         />

    <ImageView
        android:id="@+id/beleg_imageeinsatzberichtvorhanden"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:src="@drawable/ic_notizbuch_unselected" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/beleg_textbelegid"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/textbelegid" />

        <TextView
            android:id="@+id/beleg_belegid"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/abstand_liste"
            android:text="@string/belegid" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/beleg_textbelegvonbis"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/textbelegvonbis" />

        <TextView
            android:id="@+id/beleg_belegvon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/abstand_liste"
            android:text="@string/belegvon" />

        <TextView
            android:id="@+id/beleg_belegbis"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/abstand_liste"
            android:text="@string/belegbis" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/beleg_textbelegabgeschlossen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/textbelegabgeschlossen" />

        <TextView
            android:id="@+id/beleg_belegabgeschlossen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/abstand_liste"
            android:text="@string/belegabgeschlossen" />

        <TextView
            android:id="@+id/beleg_textbeleggesperrt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/textbeleggesperrt" />

        <TextView
            android:id="@+id/beleg_beleggesperrt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/abstand_liste"
            android:text="@string/beleggesperrt" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/beleg_textbelegsummestunden"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/textbelegsummestunden" />

        <TextView
            android:id="@+id/beleg_belegsummestunden"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/abstand_liste"
            android:text="@string/belegsummestunden" />
    </LinearLayout>

</LinearLayout>

【问题讨论】:

  • Photoshop。或者,如果您没有免费的 GIMP。 (gimp.org)
  • 只是让您知道,我尝试了您提供的第一张图片,它在我的 SGS II 上运行良好。
  • 嗯,它与我偶然放入清单文件的 android:theme="@android:style/Theme.Light" 有关系吗?我能做些什么来解决这个问题?

标签: android eclipse image png transparency


【解决方案1】:

您的图像可能显示为透明,但您的布局的某些部分实际上是黑色背景,并且由于图像的部分是透明的,因此背景是透明的。

尝试将ImageView的背景设置为某种颜色,看看它是否改变。

您可以在ImageView 部分中将此行添加到您的xml:

android:background="#FF0000"(红色)或其他十六进制值,看看是否显示出来。

你能发布整个xml文件吗?

编辑:我使用 Paint.net 处理图像,它是免费的,并且非常适合创建透明背景。

【讨论】:

  • 嗨,谢谢,我用 xml 代码更新了我的帖子。另请注意,我的清单中有 android:theme="@android:style/Theme.Light" (不知道这是否与问题有关,因为默认主题也是黑色......)。不幸的是,您的建议无济于事。 paint.net 会批量转换为透明 png 吗?在 irfanview 中,我可以直接点击快速连续点击透明颜色并处理很多这样的图像。
  • 更新:我现在也尝试了第二张图片。此处红色显示在 PNG 的透明区域中。只是不是第一张图片 :( 我的意思是它们都是透明的 png 图像。我不明白。
  • paint.net 工作,刚刚测试过,但我需要制作透明的 PNG 和很多...这不会很有趣
  • 这种情况只发生在那一张图片上吗?如果是这样,您是否有可能碰巧在没有 Alpha 通道的情况下保存了该图像?要使用paint.net 转换为透明ping(假设您指的是背景),您只需选择魔杖并单击背景颜色,然后按删除。这是假设背景都是一种颜色。
【解决方案2】:

好的 确认这是一个 IrfanView 错误。

如果我使用 IrfanView 插件 pngout.dll(感谢上帝存在)来保存 png(您可以在保存对话框中选择是否使用该插件),则 png 不会“损坏”。

谁会想到?

编辑:在此处下载插件http://www.irfanview.com/plugins.htm(在其中一个 zip 文件中)

edit2: ok 也可能是 eclipse 的 bug。任何程序写入或读取PNG non-standardconform,即

【讨论】:

    【解决方案3】:

    尝试使用 null 作为 xml 布局中图像视图的背景。

    android:background="@null"
    

    【讨论】:

      猜你喜欢
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 2013-11-30
      • 2015-07-11
      • 1970-01-01
      • 2023-03-09
      相关资源
      最近更新 更多