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 6:55 AM

All replies

  • What code language are you using?
    It doesn't appear to be VBA.

    Saturday, November 16, 2019 1:06 PM
  • VB.NET
    Saturday, November 16, 2019 2:05 PM
  • Hi Saulius LT,

    I can reproduce the issue with "Windows Photo". But with other software such as "Windows Photo Viewer", "paint.net", and "Paint", the issue does not occur.
    I suppose it is something buggy of "Widows Photo".

    Regards,

    Ashidacchi -- http://hokusosha.com

    Sunday, November 17, 2019 12:49 AM