问题
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.
回答1:
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);
}
回答2:
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);
}
}
来源:https://stackoverflow.com/questions/38281705/how-to-save-a-croppedbitmap