weixin_39932455
2020-12-02 05:38 阅读 0

DrawImage Transparency Problem

When I draw a image, with DrawImage the background never is transparent no matter what I do, I tried it with CreateImage from a path and from a MemoryStream, didn't try from Resources as it won't work for what I am using this

该提问来源于开源项目:michel-pi/GameOverlay.Net

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

9条回答 默认 最新

  • weixin_39625987 weixin_39625987 2020-12-02 05:38

    just saw your email so i quickly follow up...

    1. Can you provide a code example?
    2. Can you upload the image you are using?

    The library is trying to guess the best format to use with your image. it would be great to have the actual image to debug the issue.

    If you can not provide the exact image then please provide anothewr one where it isn't working aswell.

    点赞 评论 复制链接分享
  • weixin_39932455 weixin_39932455 2020-12-02 05:38

    gfx.DrawImage(gfx.CreateImage("E:/Downloads/cross-shaped-target.png"), 0, 0);

    cross-shaped-target

    点赞 评论 复制链接分享
  • weixin_39625987 weixin_39625987 2020-12-02 05:38

    Thank you!

    There is indeed a problem with my image decoder. DirectX reports several supported formats on my machine but it seems like the preferred one isn't working and thats why there is a fallback for standard RGB.

    I will use your image to create a better algorithm picking the best supported image format.

    And just to make sure... Youre not using this one liner in production? You will run out of memory pretty soon. Load the image only once and use it from there on.

    点赞 评论 复制链接分享
  • weixin_39625987 weixin_39625987 2020-12-02 05:38

    But i will do it tomorrow 😪

    点赞 评论 复制链接分享
  • weixin_39932455 weixin_39932455 2020-12-02 05:38

    Nope, not using it like this, I do load it once. This one was just for showing a fast example of the issue

    点赞 评论 复制链接分享
  • weixin_39625987 weixin_39625987 2020-12-02 05:38

    Well, unfortunately both BitmapDecoder.DecoderInfo.PixelFormats and BitmapFrameDecode.PixelFormat don't work in our case. The first one returns only RGB formats (no alpha) and the second one returns an unsupported format.

    I currently rely on the returned PixelFormat[] from the Decoder.

    My only idea is to change this behaviour to use a bruteforce approach by enumerating a list of all supported formats while prefering the ones with higher bits per pixel and alpha channel.

    I'll probably need another day to implement the sorting algorithm, caching and loop. Performance wise i see no problem when images get pre loaded. Support for the alpha channel and all different image formats is worth it i guess.

    Here a picture of your image drawn with transparency.

    Overlay drawing transparent image

    点赞 评论 复制链接分享
  • weixin_39932455 weixin_39932455 2020-12-02 05:38

    Perfect, would be very nice if this gets implemented)

    点赞 评论 复制链接分享
  • weixin_39625987 weixin_39625987 2020-12-02 05:38

    I uploaded a new NuGet package with the fixes applied.

    I got good results when trying to load png, bmp and gif images.

    If you got no more questions i will close the issue here.

    点赞 评论 复制链接分享
  • weixin_39932455 weixin_39932455 2020-12-02 05:38

    Thanks! Works very well now))

    点赞 评论 复制链接分享

相关推荐