Wezley
Wezley

Reputation: 413

Resize a WriteableBitmap in C# for WindowsPhone 8

How do I resize a WriteableBitmap to where it goes from 2768x2768 to 1500x1500?

I can't find any scalable options, and all the other code is incompatible with W

Thank you!

Upvotes: 0

Views: 1263

Answers (2)

Pradeep AJ- Msft MVP
Pradeep AJ- Msft MVP

Reputation: 600

You can resize your image using the below code

    public byte[] ChangeDimension(BitmapImage bitmapImage, int width, int height)
    {
        byte[] data = null;
        using (MemoryStream stream = new MemoryStream())
        {
            WriteableBitmap wBitmap = new WriteableBitmap(bitmapImage);
            wBitmap.SaveJpeg(stream,width, height, 0, 100);
            stream.Seek(0, SeekOrigin.Begin);
            data = stream.GetBuffer();
        }
        return data;
    }

Upvotes: 3

thumbmunkeys
thumbmunkeys

Reputation: 20764

Install the nuget package WriteableBitmapEx (writeable bitmap extensions).

It provides a Resize() extension method.

Another option would be the PictureDecoder class, it allows to load a scaled version of the image (If it's a JPEG).

Upvotes: 1

Related Questions