SAVEPICTURE Different Behavior

    In VB6 the SavePicture is used to save a graphic image from an objects Picture or Image property to a file. The resulting file will always be a .bmp file. This method is mapped to the System.Drawing.Image.Save method, which will be using the default image format, for example if the loaded image was a JPG the save method will generate a JPG. This is a subtle difference but maybe you have some other VB6 programs, or processes, test scripts or client tools that require the target file to remain a .BMP file. That is why the VBUC marks this line to allow you to review it and perform the appropiate action.

    Sample VB6

    In this case the original image was in jpg format, but VB6 only supports saving to bmp so the file format will be bmp, no matter the file extension.

    'Takes one pictureBox image and saves it to disk
    Public Sub Foo()
        SavePicture PictureBoxWithJpgImage.picture, "c:\pict1.bmp"
    End Sub

    Target VB.NET

    'Takes one pictureBox image and saves it to disk
    Public Sub Foo()
        'UPGRADE_WARNING: (2080) SavePicture was upgraded to System.Drawing.Image.Save and has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2080.aspx
        PictureBoxWithJpgImage.Image.Save("c:\pict1.bmp")
    End Sub

    Expected VB.NET

    In .NET the Save method of the Image class saves the file with the original image format, so in this case a modification should be done in order to save the image with bmp format, such as in VB6. Each case should be reviewed to determine which changes will be necessary in order to achieve functional equivalence.

    'Takes one pictureBox image and saves it to disk
    Public Sub Foo()
        PictureBoxWithJpgImage.Image.Save("c:\pict1.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
    End Sub

    Target C#

    //Takes one pictureBox image and saves it to disk
    public void Foo()
    {
        //UPGRADE_WARNING: (2080) SavePicture was upgraded to System.Drawing.Image.Save and has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2080.aspx
        PictureBoxWithJpgImage.Image.Save("c:\pict1.bmp");
    }

    Expected C#

    In .NET the Save method of the Image class saves the file with the original image format, so in this case a modification should be done in order to save the image with bmp format, such as in VB6. Each case should be reviewed to determine which changes will be necessary in order to achieve functional equivalence.

    'Takes one pictureBox image and saves it to disk
    public void Foo()
    {
        PictureBoxWithJpgImage.Image.Save("c:\pict1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
    }

     

     

    Important Resources

    Download VBUC Free Trial
    Download  Now

    It's time to eradicate VB6
    ROI of Eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    Learn More