Changing the Opacity of a Bitmap image

前端 未结 4 1329
暗喜
暗喜 2020-12-05 04:58

I have a form which has a image. I am using a slider to change the opacity of the image. So in the \"ValueChanged\" event of the slider I am calling the following method to

4条回答
  •  一整个雨季
    2020-12-05 05:33

    The ImageAttributes method will work fine with PNG as the original post has it listed, but for JPEG you need to flood fill the graphics canvas with a color first. Since this can leave a tiny undesired border, only do it if the opacity is something less than 1.0:

    if(opacity < 1.0)
    {
        // g is a Graphics object
        g.Clear(Color.White);
    }
    // set color matrix and draw image as shown in other posts
    // ...
    

提交回复
热议问题