-- Leo's gemini proxy

-- Connecting to g.mikf.pl:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

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:

        Dim format
        Select Case ComboBox1.SelectedValue
            Case "Jpeg", "JpegCMYK"
                format = ImageFormat.Jpeg
            Case "Gif", "GifCMYK"
                format = ImageFormat.Gif
            Case "Webp", "WebpCMYK"
                format = ImageFormat.Webp
            Case "Heif", "HeifCMYK"
                format = ImageFormat.Heif
            Case ""
                format = ImageFormat.Jpeg
                ComboBox1.SelectedValue = "Jpeg"
            Case Else
                Throw New ArgumentException(ComboBox1.SelectedValue)
        End Select

Added to Params() method:

        Dim formatName As String = ComboBox1.SelectedValue
        If formatName.EndsWith("CMYK") Then
            Dim cmykTrue As Short = True
            param = New EncoderParameter(Encoder.SaveAsCmyk, cmykTrue)
            obj.Param(1) = param
        End If

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.

        Catch oom As OutOfMemoryException
            MessageBox.Show("
              The file has given us an OOM because of its sheer size.
              Goodbye.
            ", "File too large", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Close()
            Return
        End Try

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

    Private Function isCMYK() As Boolean
        Return ComboBox1.SelectedItem.EndsWith("CMYK")
    End Function

I then made Codec() return

`.FirstOrDefault(CType(Nothing, ImageCodecInfo))`

instead, and that will have to be handled, so

        If result Is Nothing Then
            format = ImageFormat.Jpeg
            MessageBox.Show($"Format has been set to jpeg because {ComboBox1.SelectedItem} was not available in the system.")
            ComboBox1.SelectedItem = "Jpeg"
            result = getTheFormatFromCodecs(format, codecs)
        End If

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:

2023-02-13--195551--img.jpg

-- Response ended

-- Page fetched on Tue May 21 16:58:12 2024