I am trying to create string metadata to be stored in a png file, depending on the value of a parameter called
Dim qualityParam As Object
Dim encoderParams As Object = New Imaging.EncoderParameters(1)
Dim ImgCodec As Imaging.ImageCodecInfo
ImgCodec = GetEncoderInfo("image/png")
qualityParam = New Imaging.EncoderParameter(Imaging.Encoder.ColorDepth, 32L)
encoderParams.Param(0) = qualityParam
Dim propit As Imaging.PropertyItem = CType(System.Runtime.Serialization.FormatterServices.GetUninitializedObject(GetType(Imaging.PropertyItem)), Imaging.PropertyItem)
propit.Id = 270
propit.Type = 2
If sc_status = 3 Then
propit.Value = System.Text.Encoding.UTF8.GetBytes("HQ")
ElseIf sc_status = 5 Then
propit.Value = System.Text.Encoding.UTF8.GetBytes("LQ")
propit.Value = System.Text.Encoding.UTF8.GetBytes("UQ")
img_src.Save(file_name, ImgCodec, encoderParams)
When I have a look at what is stored in the png chunks, I expect to have in byte sequence
, corresponding to the string "LQ","HQ","UQ" plus the vbNullChar which is automatically added at the end of the png chunk.
But for a reason I ignore, I sometimes have a longer byte sequence, e.g.
which gives after using
HQ & ChrW(28) & vbBack & ChrW(1) & vbNullChar
, or sometimes
, or sometimes
I don't understand why sometimes extra bytes are added in the metadata during the
procedure. Any help is very welcome!
What I have tried:
I am a bit lost because 90% of the time, the metadata is correctly stored. I have not found what causes the extra bytes to be written. What am I doing wrong?