2

I created a cropped Bitmap and now i want to save it. I know how to save a bitmapframe, but i dont know how to convert it to a bitmapframe.

Code:

' Create an Image element.
    Dim croppedImage As New Image()
    croppedImage.Width = 200
    croppedImage.Margin = New Thickness(5)

    ' Create a CroppedBitmap based off of a xaml defined resource.
    Dim cb As New CroppedBitmap(CType(screenshot, BitmapSource), New Int32Rect(X, Y, breite, höhe))
    'select region rect
    croppedImage.Source = cb 'set image source to cropped

So I want to save the new Image as file.

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
julienduchow
  • 1,026
  • 1
  • 11
  • 29

2 Answers2

0

Hi i did the same thing in C#, i hope you can convert into vb

void saveCroppedBitmap(CroppedBitmap image,string path)
{
    FileStream mStream = new FileStream(path, FileMode.Create);
    JpegBitmapEncoder jEncoder = new JpegBitmapEncoder();
    jEncoder.Frames.Add(BitmapFrame.Create(image)); 
    jEncoder.Save(mStream);
}
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
-1
private void CropBitmap(BitmapFrame bitmapFrame,int height,string filename,BitmapEncoder encoder)
{
    CroppedBitmap croppedBitmap = new CroppedBitmap(bitmapFrame, new Int32Rect(0,0,(int)bitmapFrame.Width, height));

    encoder.Frames.Add(BitmapFrame.Create(croppedBitmap));

    using (System.IO.FileStream fs = File.Create(filename))
    {
        encoder.Save(fs);
    }

}
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Jabir E
  • 21
  • 4