Getting back to the image compressor WinForms app while on a train
2023-02-13
I went to ComboBox1 properties and opened the Items (Collection) to see just one line "JPG". I replace that with lines: Jpeg JpegCMYK Gif GifCMYK Webp WebpCMYK Heif HeifCMYK
Added to Codec() method:
Added to Params() method:
It then turned out I may need to add a `Nothing` case to the `""` empty string case. And then it turned out that despite Codec and Params being called to supply argument values in that order, Params seems to be called first or simultaneously. I decided to localize the variable to ensure Codec gets called first.
While trying to test that, I accidentally chose an mp4 file instead of an image: so it turned out, I needed to catch `System.OutOfMemoryException` on the `Image.FromFile` call.
I then decided to make the earlier things
`Select Case ComboBox1.SelectedText` (but with setting `ComboBox1.SelectedValue = "Jpeg"`) and `Dim formatName As String = ComboBox1.SelectedText`, respectively.
And only then I debugged and it turns out I should have used `SelectedItem` everywhere, instead.
And I then added a handler for ComboBox1.SelectionChangeCommitted that just calls Render().
I then moved the `Dim formatName` in `Params` to the top and made the EncoderParameters constructor get a
`If(formatName.EndsWith("CMYK"), 2, 1)`
instead, and then I made the IDE abstract the EndsWith into a method along with getting the SelectedItem, and then inlined the variable, just to get
I then made Codec() return
`.FirstOrDefault(CType(Nothing, ImageCodecInfo))`
instead, and that will have to be handled, so
having had extracted a method out of the Select with FirstOrDefault, but still using the `codecs` array, while I should cache both from the start really.
And we will just have to start with checking which are available and removing them from ComboBox1's Items Collection.
I then decided to add a simple
`ToolStripStatusLabel1.Text = compressed.Length.ToString`
at the end of `Render()`. Worked liked a charm and shown us that the Quality parameter doesn't affect Gif, nor does our CMYK Jpeg option change a thing as the sizes are the same as with non-CMYK. We gotta implement saving to be able to actually inspect things as files.
See me with an external display in a train: