【问题标题】:How to display a PNG image with transparent background from .Net in Android?如何在Android中从.Net显示具有透明背景的PNG图像?
【发布时间】:2014-03-21 09:27:40
【问题描述】:

这是我在.NET 上使用的方法来创建发送到android App 的字符串,图像是System.Drawing.ImageBitmap 中输入转换:

Public Shared Function SerializeObject(ByVal objeto As Bitmap) As String        

    Dim bitmapBytes As Byte()
    Dim stream As New System.IO.MemoryStream

    objeto.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)
    bitmapBytes = stream.ToArray

    stream.Flush()
    stream.Dispose()

    Dim str1 = Convert.ToBase64String(bitmapBytes)
    Return str1
End Function

这是创建图像的android方法:

public static Bitmap GetObjectBitmap(String str) {
    Bitmap bm;

    try {
       byte [] encodeByte=Base64.decode(str.trim(), Base64.DEFAULT);
       bm = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);    
    } catch(Exception e) {
        e.getMessage();
        bm = null;
    }
    return bm;
}

问题是图片在ImageView中显示,背景是黑色而不是透明。

【问题讨论】:

  • 我不知道 bmp 格式有透明度...

标签: android .net png transparency


【解决方案1】:

您正在将图像保存为 abmp 格式,但您需要将其保存为 png 格式。

从您的代码中更改以下行

objeto.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)

到这里

objeto.Save(stream, System.Drawing.Imaging.ImageFormat.Png)

【讨论】:

    猜你喜欢
    • 2021-08-08
    • 2013-09-26
    • 1970-01-01
    • 2018-10-31
    • 2023-04-10
    • 1970-01-01
    • 2012-02-26
    • 2012-12-19
    • 1970-01-01
    相关资源
    最近更新 更多