English 中文(简体)
幻灯片 具有透明PNG形象的黑人背景
原标题:Glide images shows Black background with transparent PNG image, Android

我正在利用冰川展示URL图像。 当我有透明的PNG时,它显示出黑色的反向。 是否有任何办法调整山崩,以显示这些透明形象,或至少隐蔽的透明度以达到白人?

感谢。

问题回答

如果您正在使用,则 它赢得的LOSSLESS在第29号及以下文稿上是透明的。

    override fun applyOptions(context: Context, builder: GlideBuilder) {
        super.applyOptions(context, builder)
        val memoryCacheSizeBytes = 1024 * 1024 * 100 // 100mb
        builder.setMemoryCache(LruResourceCache(memoryCacheSizeBytes.toLong()))
        builder.setDefaultRequestOptions(requestOptions(context))

        builder.apply {
            requestOptions(context)
        }
    }

    private fun requestOptions(context: Context): RequestOptions {

        val compressFormat = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            Bitmap.CompressFormat.WEBP_LOSSY
        } else {
            Bitmap.CompressFormat.PNG
        }
        return RequestOptions()
            .signature(
                ObjectKey(
                    System.currentTimeMillis() / (24 * 60 * 60 * 1000)
                )
            )
            .encodeFormat(compressFormat)
            .encodeQuality(80)
            .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
            .skipMemoryCache(false)

    }

使用地势和滑坡的原木,而不是可以()和变形(CenterInside())也造成这种情况。

I encountered similar issue recently, with glide version 4.14.2. By borrowing the idea from this answer s comment, I overcome this problem in glide with a customized bitmap transformation.

class HasAlpha: BitmapTransformation() {
    companion object {
        private const val ID = "com.bumptech.glide.transformations.HasAlpha"
        private val ID_BYTES = ID.toByteArray(CHARSET)
    }

    override fun updateDiskCacheKey(messageDigest: MessageDigest) {
        messageDigest.update(ID_BYTES)
    }

    override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap {
        toTransform.setHasAlpha(true)
        return toTransform
    }

    override fun equals(other: Any?): Boolean {
        return other is HasAlpha
    }

    override fun hashCode(): Int {
        return ID.hashCode()
    }
}

然后在装上图像时适用上述转变。

Glide.with(this).load(url).transform(HasAlpha()).into(imageView)

我不相信它会在某些版本的冰川中产生暂时的 b,也不相信它会以任何一种透明渠道制作任何形式的图像,而我的设想中的形象是完全透明的。 希望任何人来到这里会有所帮助。





相关问题
PHP gdLib 8-Bit PNG with alpha

how is it possible to save my image, created with gd, as an png-8? it saves as gif with transparent channel well - but I want to use png-8. Best Regards, Beerweasle

How does the Mac OS X Finder recognize a PNG file?

I have a file which was originally named foo in the Finder. If I get info for the file, the Finder recognizes it as "Kind: Plain text". If I rename the file as foo.png , Finder then recognizes ...

Reading Alpha of a PNG Pixel. Fast way via pure Python?

I am having an issue with an embedded 64bit Python instance not liking PIL. Before i start exhausting more methods to get a compiled image editor to read the pixels for me (such as ImageMagick) i am ...

Direct 2D gnuplot PNG animation?

Can anyone please confirm that yes/no Gnuplot 4.5 (on CVS) can output 2D animated PNG files? I have numerous datasets but one line that I d like to show iteratively in 3 different places in my graph. ...

Mask white color out of PNG image on iPhone

I know that there are already 2 relevant posts on that, but it s not clear... So the case is this...: I have a UIImage which consists of a png file requested from a url on the net. Is it possible to ...

PNG transparency in Interface Builder

I m adding an Image View in Interface Builder with a transparent PNG (A logo in the Navigation Bar) but the transparent pixels seems to render as white.. I searched for PNG in Interface Builder but ...

热门标签