Page 1 of 2

Possible inventory save Image bug in 7.1

PostPosted: Mon Jul 23, 2018 5:11 pm
by SBarnes
Hi Mike,

in trying to save out an image in 7.1 the error below is produced, the same image works fine in 7.0.175 as do other images that don't work in 7.1, images brought in using the import utility have the same problem.


save image error.jpg

Re: Possible inventory save Image bug in 7.1

PostPosted: Mon Jul 23, 2018 5:31 pm
by Scott.Pearce
Can you please test in 7.1.8.0?

Download from:

ftp://ftp.jiwa.com.au/07.01.08.00/Setup.exe

https://service.jiwa.com.au/browse/DEV-6757 may have sorted it.

Re: Possible inventory save Image bug in 7.1

PostPosted: Mon Jul 23, 2018 5:43 pm
by Mike.Sheen
Scott.Pearce wrote:https://service.jiwa.com.au/browse/DEV-6757 may have sorted it.


Oh, I doubt that issue is related - that was a very specific bug related to icon maintenance, not images. But I do recall an issue similar to what Stuart is reporting for Staff Maintenance images that was fixed in the last few months - DEV-6557 - which I think is the one this was fixed in - version 07.01.02.00.

Re: Possible inventory save Image bug in 7.1

PostPosted: Mon Jul 23, 2018 5:48 pm
by Mike.Sheen
Yep - I can confirm DEV-6557 addressed this issue in staff and Inventory maintenance forms.

The problem seemed to only occur when saving as certain image types. For instance - I believe JPG causes the error, but not PNG.

Re: Possible inventory save Image bug in 7.1

PostPosted: Mon Jul 23, 2018 5:50 pm
by SBarnes
No all image types produce the error, it creates a file but its blank.

By the way reverting to the default and saving that out works fine.

Re: Possible inventory save Image bug in 7.1  Topic is solved

PostPosted: Mon Jul 23, 2018 7:14 pm
by Mike.Sheen
Yes - we found it was when the image was jpg and you tried to save as png or vice-versa.

The code we ended up with (including the old problematic code commented out) is:

Code: Select all
' See https://stackoverflow.com/questions/1053052/a-generic-error-occurred-in-gdi-jpeg-image-to-memorystream
' And https://stackoverflow.com/questions/336387/image-save-throws-a-gdi-exception-because-the-memory-stream-is-closed
' GDI errors may occur when saving if you don't keep the stream open that the image was created from.
'
' So, the following will fail with "A generic error occurred in GDI+" if the image was jpg and saving as png, or vice versa:
'Using image As System.Drawing.Image = JiwaApplication.Manager.ByteArrayToImage(If(Inventory.Picture Is Nothing, Inventory.SystemSettings.DefaultPicture, Inventory.Picture))
'    Select Case DialogSave.FilterIndex
'        Case 1
'            image.Save(DialogSave.FileName, System.Drawing.Imaging.ImageFormat.Png)
'        Case 2
'            image.Save(DialogSave.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
'        Case 3
'            image.Save(DialogSave.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
'        Case 4
'            image.Save(DialogSave.FileName, System.Drawing.Imaging.ImageFormat.Gif)
'    End Select
'End Using

' But, this works!
Using streamBitmap As New System.IO.MemoryStream(If(Inventory.Picture Is Nothing, Inventory.SystemSettings.DefaultPicture, Inventory.Picture))
   Using img = System.Drawing.Image.FromStream(streamBitmap)
      Select Case DialogSave.FilterIndex
         Case 1
            img.Save(DialogSave.FileName, System.Drawing.Imaging.ImageFormat.Png)
         Case 2
            img.Save(DialogSave.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
         Case 3
            img.Save(DialogSave.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
         Case 4
            img.Save(DialogSave.FileName, System.Drawing.Imaging.ImageFormat.Gif)
      End Select
   End Using
End Using

Re: Possible inventory save Image bug in 7.1

PostPosted: Mon Jul 23, 2018 7:23 pm
by SBarnes
Hi Mike,

Thanks for letting me know, by the way I suppose there is a similar thing with the web api pictures and documents i.e. you don't know the file/media type.

Re: Possible inventory save Image bug in 7.1

PostPosted: Mon Jul 23, 2018 7:39 pm
by Mike.Sheen
SBarnes wrote:Hi Mike,

Thanks for letting me know, by the way I suppose there is a similar thing with the web api pictures and documents i.e. you don't know the file/media type.


As far as the web api is concerned, images and documents are just byte arrays - but you can examine the first few bytes of the array to know with a reasonable degree of confidence what the image type is.

Converting from one type to another, however, is a completely different problem and not really within the scope of our web api.

Re: Possible inventory save Image bug in 7.1

PostPosted: Mon Jul 23, 2018 7:42 pm
by SBarnes
Yes I know that trick but what about documents?

Re: Possible inventory save Image bug in 7.1

PostPosted: Mon Jul 23, 2018 10:31 pm
by Mike.Sheen
SBarnes wrote:Yes I know that trick but what about documents?


Hi Stuart,

Documents are - like the images in inventory maintenance - merely byte arrays as far as the web api is concerned - so the same applies - you can examine the first few bytes and from that determine if it is an image and what type of image.

We could add a static helper method to our bits - whether it be the web api or our assemblies to pass in a byte array and it return the image type (or "unknown") if that is any help.

Let us know if that would be useful - or if not let us know what ideally you'd want from us.

Mike