7

I am trying to convert a CroppedBitmap to BitmapImage * EDIT:Without using a memorystream.*

I have tried to directly convert it, seems that is not an option. This should't be that hard.

I am attempting to cut out part of a BitmapImage, and create a BitmapImage that contains only the new cropped Bitmap.

General Grey
  • 3,598
  • 2
  • 25
  • 32

2 Answers2

4

It would seem a BitmapImage is a specialized version of BitmapSource (which is what a CroppedBitmap is). You can easily convert from Image to source, but not the otherway around.

This answer likely works, though I never looked into it.

BitmapSource to BitmapImage

The easiest solution for me was to convert all my BitmapImages into BitmapSources. I didn't even have to edit any other code. I guess I wasn't using the specialized parts.

Community
  • 1
  • 1
General Grey
  • 3,598
  • 2
  • 25
  • 32
  • 1
    For many use cases it would even be sufficient to use `ImageSource`, which is the base class of `BitmapSource`. For example the `Source` property of the `Image` control is of type `ImageSource`. – Clemens Jan 22 '14 at 07:11
  • 1
    And this is what MSDN say about `BitmapImage` (in the Remarks [here](http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx)): *BitmapImage primarily exists to support Extensible Application Markup Language (XAML) syntax and introduces additional properties for bitmap loading that are not defined by BitmapSource.`. – Clemens Jan 22 '14 at 07:13
0

you can try this Bitmap bm = new Bitmap(Image file path or image stream); after that use the save function like this bm.Save(Image path,format);

Ravi Verma
  • 182
  • 1
  • 3
  • 12
  • Not sure I follow. Bitmap is used in Winforms, BitmapImage/BitmapSource are from WPF. Are you suggesting mixing the two?... how do you get the BitmapImage into a Bitmap to Beginwith? – General Grey Jan 22 '14 at 06:47