Question Jpeg XR

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
can you save an image in the jpeg xr format?
 
i have found a function that can save a file to the format.

VB.NET:
    Private Sub FileToWmp(ByVal inFile As String,ByVal outFile As String)
        Dim bdFile As BitmapDecoder = Nothing        ' Container for bitmap frames

        Dim readFile As FileStream = File.OpenRead(inFile)        ' Read the source file into a FileStream object

        ' Set the BitmapDecoder object from the source file
        bdFile = BitmapDecoder.Create(readFile, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None)

        Dim writeFile As FileStream = File.OpenWrite(outFile)        ' Prepare the output file

        Dim wbeFile As New WmpBitmapEncoder()        ' All the magic done by WmpBitmapEncoder

        wbeFile.ImageQualityLevel = 0.9F        ' Set the quality level to... pretty good

        wbeFile.Frames.Add(bdFile.Frames(0))        ' Add the bitmap frame to the encoder object

        wbeFile.Save(writeFile)        ' Write the output file

        writeFile.Close()
        readFile.Close()
    End Sub

but this require an infile, can it be changed so that it use an image instead of a file?
 
Ok here is the new version of the function. Does it look correct? It gave no error and saved the file. :)

VB.NET:
    Private Sub FileToWmp(ByVal outFile As String, ByVal img As Image, ByVal quality As Long)

        Dim bit As Bitmap = New Bitmap(img, img.Width, img.Height)

        Dim bitmap As IntPtr = bit.GetHbitmap
        Dim palette As IntPtr
        Dim sourceRect As Windows.Int32Rect = New Windows.Int32Rect(0, 0, img.Width, img.Height)
        Dim sizeOptions As BitmapSizeOptions = BitmapSizeOptions.FromEmptyOptions

        Dim image As BitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( _
                                    bitmap, palette, sourceRect, sizeOptions)


        Dim stream As New FileStream(outFile, FileMode.Create)

        Dim encoder As New WmpBitmapEncoder()        ' All the magic done by WmpBitmapEncoder

        encoder.ImageQualityLevel = quality / 100       ' Set the quality level to a percentage

        encoder.Frames.Add(BitmapFrame.Create(image))        ' Add the bitmap frame to the encoder object

        encoder.Save(stream)

        stream.Close()

    End Sub
also can you set the bit depth to 24bit instead of the default 32bit?
 
Last edited:
Back
Top