Smrf.NodeXL.ExcelTemplate.SubgraphImageCreator.SaveBitmap C# (CSharp) Method

SaveBitmap() protected method

protected SaveBitmap ( Bitmap oBitmap, String sFileNameWithPath, ImageFormat eImageFormat ) : void
oBitmap System.Drawing.Bitmap
sFileNameWithPath String
eImageFormat System.Drawing.Imaging.ImageFormat
return void
    SaveBitmap
    (
        Bitmap oBitmap,
        String sFileNameWithPath,
        ImageFormat eImageFormat
    )
    {
        Debug.Assert(oBitmap != null);
        Debug.Assert( !String.IsNullOrEmpty(sFileNameWithPath) );

        // Check whether the file exists and is read-only.

        if ( File.Exists(sFileNameWithPath) &&

            ( (File.GetAttributes(sFileNameWithPath)
                & FileAttributes.ReadOnly) != 0 ) )
        {
            throw new IOException( String.Format(

                "The file \"{0}\" is read-only and can't be overwritten."
                + "  Delete the file and create the images again."
                ,
                sFileNameWithPath
                ) );
        }

        if ( sFileNameWithPath.Length > FileUtil.MaximumFileNameLength
            ||
            Path.GetDirectoryName(sFileNameWithPath).Length >
                FileUtil.MaximumFolderNameLength
            )
        {
            throw new IOException( String.Format(

                "The subgraph image \"{0}\" can't be saved because the file"
                + " name is too long.  File names can't be longer than {1}"
                + " characters, and folder names can't be longer than {2}"
                + " characters.  Either use a subgraph image folder with a"
                + " shorter name, or shorten the vertex name."
                ,
                sFileNameWithPath,
                FileUtil.MaximumFileNameLength,
                FileUtil.MaximumFolderNameLength
                ) );
        }

        // Save the image.

        GraphicsUtil.SaveHighQualityImage(oBitmap, sFileNameWithPath,
            eImageFormat);
    }