When we have an [IplImage](http://opencv.willowgarage.com/documentation/basic_structures.html#iplimage), how can we save it so we can use it later, or view it as an image outside of our code (such as via png, or jpeg)?

As a code example, I have the following:

```
void SaveImage()
{
    CvSize size;
    IplImage *rgb_img;
    int i = 0;

    size.height = HEIGHT;
    size.width = WIDTH;

    rgb_img = cvCreateImageHeader(size, IPL_DEPTH_8U, 3);
    rgb_img->imageData = my_device.ColorBuffer;
    rgb_img->imageDataOrigin = rgb_img->imageData;

    /*for (i = 2; i < rgb_img->imageSize; i+= 3)
    {
        // confirming all values print correctly
        printf("%d, ", rgb_img->imageData[i]);
    }*/

    cvSaveImage("foo.png",rgb_img);
}

```

I have printed out all of the values in the commented out for loop, and it seems like the data is in the buffer correctly. Using cvShowImage to display the image also works correctly, so it seems like the structure of the image is fine.