Help and Support

Save method of Bitmap class does not truncate file size

Article ID:312119
Last Review:December 3, 2007
Revision:4.7
This article was previously published under Q312119
Note Microsoft Visual C++ .NET (2002) supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code.
Note Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.
The following .NET Framework Class Library namespaces are referenced in this article:
System.Drawing
System.IO
On This Page

SYMPTOMS

When you invoke the Save method of the Bitmap class to overwrite an existing file of the same name, the resulting file is not truncated as expected.

Back to the top

CAUSE

This behavior occurs because the implementation of the Save method does not truncate any already existing file.

Back to the top

RESOLUTION

To work around this issue, delete the file before you invoke the Bitmap.Save method.

The file can be deleted in Visual Basic .NET or in Visual Basic 2005 and C# by using the System.IO.File.Delete method provided by the .NET Framework in the System.IO namespace.

Back to the top

MORE INFORMATION

Steps to reproduce the problem

1.Create a Bitmap class by using the version of the Bitmap constructor that accepts a file name.
2.Create a file with the same file name and extension as the target file name to be used in the Save method. Ensure that this file is larger than the file used to construct the Bitmap.
3.Use the Bitmap.Save operator to save the Bitmap object by using the file name of the file that you created in step 2. Note that the resulting file is a copy of the image file, and that the file size has not changed from that of the pre-existing file.

Note This issue can also occur with the System.Drawing.Image class.

Back to the top


APPLIES TO
Microsoft .NET Framework 2.0
Microsoft .NET Framework Class Libraries 1.0
Microsoft Visual C++ 2005 Express Edition
Microsoft Visual C++ .NET 2003 Standard Edition
Microsoft Visual C++ .NET 2002 Standard Edition
Microsoft .NET Framework 1.0
Microsoft Visual Basic .NET 2002 Standard Edition
Microsoft Visual Basic 2005
Microsoft Visual C# .NET 2002 Standard Edition
Microsoft Visual C# 2005

Back to the top

Keywords: 
kbreadme kbprb kbvs2005applies kbvs2005swept KB312119

Back to the top

Article Translations

 

Other Support Options

  • Contact Microsoft
    Phone Numbers, Support Options and Pricing, Online Help, and more.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.