[Gambas-user] [Gambas Bug Tracker] Bug #1044: Gambas should trow an error or at least a warning when loading corrupted images

bugtracker at ...3416... bugtracker at ...3416...
Tue Jan 10 14:50:32 CET 2017


http://gambaswiki.org/bugtracker/edit?object=BUG.1044&from=L21haW4-

Comment #5 by Antonio OREFICE:

The example provided by Fabien does indeed reproduce the "bug", but i made another one, attached.
I also noticed that with gb.gtk it does (prints "image is corrupted"), while gb.qt4 and gb.qt5 always print "Image is fine"

Public Sub Form_Open()
  Dim hFile As File
  Dim mydata As Byte[]
  Dim sFileName As String = "/tmp/image.jpg"
  Dim img As New Image(640, 480, Color.black) 'make a black image
  Dim i As Long
  Dim bByte As Byte
  Dim bBytes As New Byte[]
  Dim iLen As Long
  img.Save(sFileName) 'save it to disk
  
  hFile = Open sFileName For Read 
  
  iLen = Stat(sFileName).Size
  
  For i = 0 To iLen - 1 'read the image file in memory
    Read #hFile, bByte
    bBytes.Add(bByte)
  Next 'i
  
  hFile.Close()
  Kill sFileName 'delete the image file

  hFile = Open sFileName For Read Write Create


  For i = 0 To ((iLen - 1) Div 2) 'write it to disk again, but only the first half
    Write #hFile, bBytes[i] As Byte
  Next 'i
  
  hFile.Close()
  
  Try img = Image.Load(sFileName) 'try to load the corrupted image
  
  If Error Then 
    Print "Image is corrupted" '<--- this is printed with gtk2 and gtk3
      Else
    Print "Image is fine" '<--- this is printed with qt4 and qt5
  Endif

End






More information about the User mailing list