If I trying to convert a RAW-Image (CR2) to a WDP (HDP)-Image so i loose the
Metadata!
How can i fix it?
Public Sub SaveAsHdp(ByVal sourceStream As System.IO.Stream, ByVal
destinationStream As System.IO.Stream, ByVal quality As Int32)
If ((sourceStream IsNot Nothing) AndAlso (sourceStream.CanRead))
And ((destinationStream IsNot Nothing) AndAlso (destinationStream.CanWrite))
Then
Dim decoder As System.Windows.Media.Imaging.BitmapDecoder =
Nothing
Try
decoder =
System.Windows.Media.Imaging.BitmapDecoder.Create(sourceStream,
Windows.Media.Imaging.BitmapCreateOptions.PreservePixelFormat Or
Windows.Media.Imaging.BitmapCreateOptions.IgnoreColorProfile,
System.Windows.Media.Imaging.BitmapCacheOption.Default)
If (decoder.Frames.Count > 0) AndAlso (decoder.Frames(0)
IsNot Nothing) Then
Dim destinationFrame As
Windows.Media.Imaging.BitmapFrame = Nothing
Dim imageEncoder As New
System.Windows.Media.Imaging.WmpBitmapEncoder()
Try
destinationFrame =
Windows.Media.Imaging.BitmapFrame.Create(decoder.Frames(0),
decoder.Frames(0).Thumbnail, decoder.Frames(0).Metadata.Clone(),
decoder.ColorContexts)
If quality <= 0 Then quality = 1
If quality > 100 Then quality = 100
imageEncoder.ImageQualityLevel = quality / 100
imageEncoder.Frames.Add(destinationFrame)
imageEncoder.Save(destinationStream)
destinationStream.Flush()
Catch ex As Exception
Throw
Finally
destinationFrame = Nothing
imageEncoder = Nothing
End Try
End If
Catch ex As Exception
Throw New System.IO.FileFormatException("FileFormat not
supported")
Finally
decoder = Nothing
End Try
Else
Throw New System.ArgumentOutOfRangeException("Can't handle
Stream-Argument!")
End If
End Sub
|