---
title: "How to Change Size of Image?"  
description: "How to Change Size of Image?"  
author: "Anonymous User"  
published: 2013-09-23  
updated: 2013-09-23  
canonical: https://www.mindstick.com/forum/1479/how-to-change-size-of-image  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# How to Change Size of Image?

I [am getting](https://www.mindstick.com/forum/34179/i-am-getting-error-while-assigning-the-data-to-the-array-list) an [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) from the CameraCaptureTask, and I would like to be able to make the image much smaller before [saving](https://www.mindstick.com/blog/11865/guide-to-saving-15-for-retirement). The width and height are automatically set to the highest [resolution](https://www.mindstick.com/articles/12502/looking-for-an-mba-degree-we-guide-you-with-the-perfect-resolution), which is much more than what I need. I have been [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to get the image, change the [dimensions](https://www.mindstick.com/forum/1834/c-sharp-xaml-how-to-modify-the-dimensions-of-the-rows-and-the-columns-of-a-grid), and then attempt to save, although I am getting errors.

## MainPage.xaml.cs

```
private void cameraTask_Completed(object sender,PhotoResult e)    {        if(e.TaskResult == TaskResult.OK)        {           
BitmapImage bmi = new BitmapImage();           
bmi.SetSource(e.ChosenPhoto);           
//MessageBox.Show(bmi.PixelWidth.ToString() + "x" +bmi.PixelHeight.ToString());            var gcd= GCD(bmi.PixelWidth, bmi.PixelHeight);            varresult = string.Format("{0}:{1}", bmi.PixelWidth / gcd,bmi.PixelHeight / gcd);           
WriteableBitmap wb;            Stream stream;            switch(result)            {               
          case "3:4":                   
    wb = new WriteableBitmap(480,640);                   
        break;               
case "4:3":                   
wb = new WriteableBitmap(640,480);                   
break;               
case "9:16":                   
wb = new WriteableBitmap(448, 800);                   
break;               
case "16:9":                   
wb = new WriteableBitmap(800, 448);                   
break;            }            //Set the wb to the original stream?           
wb.SetSource(e.ChosenPhoto); //ERROR saying Use of unassigned local variable 'wb'           
//Convert the wb to a stream for saving  stream= new MemoryStream(wb.ToByteArray());//Need to replace the following line with the new image stream for saving?            //var capturedPicture = new CapturedPicture(e.OriginalFileName, e.ChosenPhoto);               var capturedPicture = new CapturedPicture(e.OriginalFileName, stream);                  }    }    public int GCD(int a, int b)    {        while (a != 0 && b != 0)        {                  if (a > b)                a %= b;            else                b %= a;        }        if (a == 0)            return b;        else            return a;    }
```

## Replies

### Reply by Sumit Kesarwani

Use the overloaded Bitmap constructor to create a re-sized image, the only thing you were missing was a cast back to the Image data type:

```
public static Image resizeImage(Image imgToResize, Size
size){   return (Image)(new
Bitmap(imgToResize, size));}yourImage = resizeImage(yourImage, new Size(50,50));
```


---

Original Source: https://www.mindstick.com/forum/1479/how-to-change-size-of-image

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
