none
Why does a saved photo disappear after a few moments when it is opened? RRS feed

  • Question

  • 1. I save a transparent picture in png format.

    2. Open the photo (with Microsoft photos) by clicking on it.

    3. The photo disappears after a moment.

    4. This problem does not occur when the picture is opaque or open with another program.

    5. How do I change the code to avoid this problem?

    Public Class Form1
        Dim img As Bitmap
        Dim px(,) As Color
        Dim im As Image = Image.FromFile("C:\Users\Saulius\Pictures\Saved Pictures\eifelis.png")
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            PictureBox1.Width = 1000
            PictureBox1.Height = PictureBox1.Width / (im.Width / im.Height)
            img = New Bitmap(im, PictureBox1.Width, PictureBox1.Height)
            PictureBox1.Image = img
            ReDim px(img.Width, img.Height)
        End Sub
        Sub tt()
            For y As Integer = 0 To img.Height - 1
                For x As Integer = 0 To img.Width - 1
                    px(x, y) = img.GetPixel(x, y)
                Next
            Next
            Dim newy, newx As Integer
            img = New Bitmap(PictureBox1.Width, PictureBox1.Height)
            PictureBox1.Image = img
            For y As Integer = 0 To img.Height - 1
                newy = Math.Ceiling(Math.Sin(Math.PI / 180.0 * ((y + 1) * (90.0 / img.Height))) * (y + 1))
                For x As Integer = 0 To img.Width - 1
                    newx = Math.Ceiling(Math.Sin(Math.PI / 180.0 * ((x + 1) * (90.0 / img.Width))) * (x + 1))
                    img.SetPixel(x, y, Color.FromArgb(50, Convert.ToInt32(px(x, newy - 1).R), Convert.ToInt32(px(x, newy - 1).G), Convert.ToInt32(px(x, newy - 1).B)))
                Next
            Next
        End Sub
        Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
    
        End Sub
        Dim j As Integer
        Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles MyBase.MouseClick
            tt()
            img.Save("C:\Users\Saulius\Desktop\photo.png", Imaging.ImageFormat.Png)
        End Sub
    End Class

    Disappear:

    This saved Picture:

    Saturday, November 16, 2019 2:14 PM

All replies

  • I can not reproduce or do not understand the problem.

    I get a resized lightened image with no transparency saved to disc when I click the form. What am I supposed to get?

    When you use alpha = 50 ie: Color.FromArgb(50,r,g,b ) that removes any transparency and replaces with that semi-opaque color.

    "3. The photo disappears after a moment."

    Which image do you mean? The original? The one you saved? The one in the application form? The one in Microsoft photos?

    "1. I save a transparent picture in png format."

    How do you do that?

    Saturday, November 16, 2019 3:17 PM
  • Hi,

    I can reproduce your problem, but after the alpha value is raised to a certain value, or using other viewing software to open the image, the picture will not disappear. You can try it, I wonder if it will have anything to do with it.

    img.SetPixel(x, y, Color.FromArgb(200, Convert.ToInt32(px(x, newy - 1).R), Convert.ToInt32(px(x, newy - 1).G), Convert.ToInt32(px(x, newy - 1).B)))

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 19, 2019 6:22 AM
    Moderator