Dear all,
I am trying to create string metadata to be stored in a png file, depending on the value of a parameter called
sc_status
.
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")
Else
propit.Value = System.Text.Encoding.UTF8.GetBytes("UQ")
End If
img_src.SetPropertyItem(propit)
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
(72,81,0)
or
(76,81,0)
or
(85,81,0)
, 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.
(72,81,28,8,1,0)
which gives after using
System.Text.Encoding.UTF8.GetString
the string
HQ & ChrW(28) & vbBack & ChrW(1) & vbNullChar
, or sometimes
(72,81,22,8,1,0)
, or sometimes
(72,81,19,8,1,0)
or sometimes
(72,81,23,8,1,0)
.
I don't understand why sometimes extra bytes are added in the metadata during the
img_src.Save
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?