locked
Changing WriteableBitmap width and height RRS feed

  • Question

  • Hello.

    There is a problem that is bugging me for ages now. How can you change WriteableBitmap object its width and height through code after they are already set.
    An example is when you're croping an image, you need to set new width and height of the image(only the cropped part). Or when you rotate it, you must switch height with width.
    Please, I would be very grateful for every help you can give! Thanks!

    Friday, February 15, 2013 2:36 PM

Answers

  • Hello Konstantinnn

    You have probably noticed that you can't directly modify the width or height properties of the WriteableBitmap objects as they are read only. Generally, you will use a source and destination WriteableBitmap object when you are doing something like cropping or rotating the image and these values will be set when the pixels are loaded into the object. There is also the approach of using BitmapTransform and BitmapEncoder along with a WriteableBitmap to crop images. Take a look at the sample project at the link below:

    http://code.msdn.microsoft.com/windowsapps/CSWin8AppCropBitmap-52fa1ad7/view/SourceCode#content

    • Proposed as answer by Jesse Jiang Tuesday, February 19, 2013 2:53 AM
    • Marked as answer by Jesse Jiang Thursday, February 21, 2013 2:09 AM
    Friday, February 15, 2013 3:31 PM

All replies

  • Hello Konstantinnn

    You have probably noticed that you can't directly modify the width or height properties of the WriteableBitmap objects as they are read only. Generally, you will use a source and destination WriteableBitmap object when you are doing something like cropping or rotating the image and these values will be set when the pixels are loaded into the object. There is also the approach of using BitmapTransform and BitmapEncoder along with a WriteableBitmap to crop images. Take a look at the sample project at the link below:

    http://code.msdn.microsoft.com/windowsapps/CSWin8AppCropBitmap-52fa1ad7/view/SourceCode#content

    • Proposed as answer by Jesse Jiang Tuesday, February 19, 2013 2:53 AM
    • Marked as answer by Jesse Jiang Thursday, February 21, 2013 2:09 AM
    Friday, February 15, 2013 3:31 PM
  • I read the license but I would like to still ask. Is there a problem if I include files and code from this example? I keep the Microsoft copyrights in the files I include..
    Friday, February 22, 2013 3:29 PM