nsCOMPtr<nsILocalFile> path; rv = NS_NewLocalFile(aPath, PR_TRUE, getter_AddRefs(path));  if (NS_FAILED(rv)) return rv;
WriteBitmap(nsString& aPath, gfxIImageFrame* aImage){  PRInt32 width, height;  aImage->GetWidth(&width);  aImage->GetHeight(&height);    PRUint8* bits;  PRUint32 length;  aImage->GetImageData(&bits, &length);  if (!bits) return NS_ERROR_FAILURE;    PRUint32 bpr;  aImage->GetImageBytesPerRow(&bpr);  PRInt32 bitCount = bpr/width;    // initialize these bitmap structs which we will later  // serialize directly to the head of the bitmap file  LPBITMAPINFOHEADER bmi = (LPBITMAPINFOHEADER)new BITMAPINFO;  bmi->biSize = sizeof(BITMAPINFOHEADER);  bmi->biWidth = width;  bmi->biHeight = height;  bmi->biPlanes = 1;  bmi->biBitCount = (WORD)bitCount*8;  bmi->biCompression = BI_RGB;  bmi->biSizeImage = 0; // don't need to set this if bmp is uncompressed  bmi->biXPelsPerMeter = 0;  bmi->biYPelsPerMeter = 0;  bmi->biClrUsed = 0;  bmi->biClrImportant = 0;    BITMAPFILEHEADER bf;  bf.bfType = 0x4D42; // 'BM'  bf.bfReserved1 = 0;  bf.bfReserved2 = 0;  bf.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);  bf.bfSize = bf.bfOffBits + bmi->biSizeImage;  // get a file output stream  nsresult rv;  nsCOMPtr<nsILocalFile> path;  rv = NS_NewLocalFile(aPath, PR_TRUE, getter_AddRefs(path));    if (NS_FAILED(rv))    return rv;  nsCOMPtr<nsIOutputStream> stream;  NS_NewLocalFileOutputStream(getter_AddRefs(stream), path);  // write the bitmap headers and rgb pixel data to the file  rv = NS_ERROR_FAILURE;  if (stream) {    PRUint32 written;    stream->Write((const char*)&bf, sizeof(BITMAPFILEHEADER), &written);    if (written == sizeof(BITMAPFILEHEADER)) {      stream->Write((const char*)bmi, sizeof(BITMAPINFOHEADER), &written);      if (written == sizeof(BITMAPINFOHEADER)) {        stream->Write((const char*)bits, length, &written);        if (written == length)          rv = NS_OK;      }    }      stream->Close();  }    return rv;}