Image.Save メソッド (String, ImageFormat)
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim instance As Image Dim filename As String Dim format As ImageFormat instance.Save(filename, format)
- format
この Image の ImageFormat。


ビットマップを型から作成する方法、および Save メソッドを使用する方法を次のコード例に示します。この例を実行するには、コードを Windows フォームに貼り付けます。フォームの Paint イベントを処理し、ConstructFromResourceSaveAsGif メソッドを呼び出し、e を PaintEventArgs として渡します。
Private Sub ConstructFromResourceSaveAsGif(ByVal e As PaintEventArgs) ' Construct a bitmap from the button image resource. Dim bmp1 As New Bitmap(GetType(Button), "Button.bmp") ' Save the image as a GIF. bmp1.Save("c:\button.gif", System.Drawing.Imaging.ImageFormat.Gif) ' Construct a new image from the GIF file. Dim bmp2 As New Bitmap("c:\button.gif") ' Draw the two images. e.Graphics.DrawImage(bmp1, New Point(10, 10)) e.Graphics.DrawImage(bmp2, New Point(10, 40)) ' Dispose of the image files. bmp1.Dispose() bmp2.Dispose() End Sub
private void ConstructFromResourceSaveAsGif(PaintEventArgs e) { // Construct a bitmap from the button image resource. Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp"); // Save the image as a GIF. bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif); // Construct a new image from the GIF file. Bitmap bmp2 = new Bitmap("c:\\button.gif"); // Draw the two images. e.Graphics.DrawImage(bmp1, new Point(10, 10)); e.Graphics.DrawImage(bmp2, new Point(10, 40)); // Dispose of the image files. bmp1.Dispose(); bmp2.Dispose(); }
private: void ConstructFromResourceSaveAsGif(PaintEventArgs^ e) { // Construct a bitmap from the button image resource. Bitmap^ bmp1 = gcnew Bitmap(Button::typeid, "Button.bmp"); String^ savePath = Environment::GetEnvironmentVariable("TEMP") + "\\Button.bmp"; try { // Save the image as a GIF. bmp1->Save(savePath, System::Drawing::Imaging::ImageFormat::Gif); } catch (IOException^) { // Carry on regardless } // Construct a new image from the GIF file. Bitmap^ bmp2 = nullptr; if (File::Exists(savePath)) { bmp2 = gcnew Bitmap(savePath); } // Draw the two images. e->Graphics->DrawImage(bmp1, Point(10, 10)); // If bmp1 did not save to disk, bmp2 may be null if (bmp2 != nullptr) { e->Graphics->DrawImage(bmp2, Point(10, 40)); } // Dispose of the image files. delete bmp1; if (bmp2 != nullptr) { delete bmp2; } }
private void ConstructFromResourceSaveAsGif(PaintEventArgs e) { // Construct a bitmap from the button image resource. Bitmap bmp1 = new Bitmap(Button.class.ToType(), "Button.bmp"); // Save the image as a GIF. bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.get_Gif()); // Construct a new image from the GIF file. Bitmap bmp2 = new Bitmap("c:\\button.gif"); // Draw the two images. e.get_Graphics().DrawImage(bmp1, new Point(10, 10)); e.get_Graphics().DrawImage(bmp2, new Point(10, 40)); // Dispose of the image files. bmp1.Dispose(); bmp2.Dispose(); } //ConstructFromResourceSaveAsGif

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Image.Save メソッド (String)
アセンブリ: System.Drawing (system.drawing.dll 内)




Save メソッドを呼び出す方法を次のコード例に示します。この例は、Windows フォームでの使用を意図してデザインされています。Button1 および Button5 という名前の 2 つのボタンを格納するフォームを作成します。コードをフォームに貼り付け、対応するボタンの Click イベントに各メソッドを関連付けます。
Dim image1 As Bitmap Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Try ' Retrieve the image. image1 = New Bitmap( _ "C:\Documents and Settings\All Users\Documents\My Music\music.bmp", _ True) Dim x, y As Integer ' Loop through the images pixels to reset color. For x = 0 To image1.Width - 1 For y = 0 To image1.Height - 1 Dim pixelColor As Color = image1.GetPixel(x, y) Dim newColor As Color = _ Color.FromArgb(pixelColor.R, 0, 0) image1.SetPixel(x, y, newColor) Next Next ' Set the PictureBox to display the image. PictureBox1.Image = image1 ' Display the pixel format in Label1. Label1.Text = "Pixel format: " + image1.PixelFormat.ToString() Catch ex As ArgumentException MessageBox.Show("There was an error." _ & "Check the path to the image file.") End Try End Sub
Bitmap image1; private void Button1_Click(System.Object sender, System.EventArgs e) { try { // Retrieve the image. image1 = new Bitmap(@"C:\Documents and Settings\All Users\" + @"Documents\My Music\music.bmp", true); int x, y; // Loop through the images pixels to reset color. for(x=0; x<image1.Width; x++) { for(y=0; y<image1.Height; y++) { Color pixelColor = image1.GetPixel(x, y); Color newColor = Color.FromArgb(pixelColor.R, 0, 0); image1.SetPixel(x, y, newColor); } } // Set the PictureBox to display the image. PictureBox1.Image = image1; // Display the pixel format in Label1. Label1.Text = "Pixel format: "+image1.PixelFormat.ToString(); } catch(ArgumentException) { MessageBox.Show("There was an error." + "Check the path to the image file."); } }
private: Bitmap^ image1; void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ ) { try { // Retrieve the image. image1 = gcnew Bitmap( "C:\\Documents and Settings\\All Users\\" "Documents\\My Music\\music.bmp",true ); int x; int y; // Loop through the images pixels to reset color. for ( x = 0; x < image1->Width; x++ ) { for ( y = 0; y < image1->Height; y++ ) { Color pixelColor = image1->GetPixel( x, y ); Color newColor = Color::FromArgb( pixelColor.R, 0, 0 ); image1->SetPixel( x, y, newColor ); } } // Set the PictureBox to display the image. PictureBox1->Image = image1; // Display the pixel format in Label1. Label1->Text = String::Format( "Pixel format: {0}", image1->PixelFormat ); } catch ( ArgumentException^ ) { MessageBox::Show( "There was an error." "Check the path to the image file." ); } }
private Bitmap image1; private void button1_Click(Object sender, System.EventArgs e) { try { // Retrieve the image. image1 = new Bitmap("C:\\Documents and Settings\\All Users\\" + "Documents\\My Music\\music.bmp", true); int x, y; // Loop through the images pixels to reset color. for (x = 0; x < image1.get_Width(); x++) { for (y = 0; y < image1.get_Height(); y++) { Color pixelColor = image1.GetPixel(x, y); Color newColor = Color.FromArgb(pixelColor.get_R(), 0, 0); image1.SetPixel(x, y, newColor); } } // Set the PictureBox to display the image. pictureBox1.set_Image(image1); // Display the pixel format in label1. label1.set_Text("Pixel format: " + image1.get_PixelFormat().ToString()); } catch (ArgumentException exp) { MessageBox.Show(("There was an error." + "Check the path to the image file.")); } } //button1_Click
Private Sub Button5_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button5.Click Try If Not (image1 Is Nothing) Then image1.Save("c:\myBitmap.bmp") Button5.Text = "Saved file." End If Catch ex As Exception MessageBox.Show("There was a problem saving the file." _ & "Check the file permissions.") End Try End Sub
private void Button5_Click(System.Object sender, System.EventArgs e) { try { if (image1 != null) { image1.Save("c:\\myBitmap.bmp"); Button5.Text = "Saved file."; } } catch(Exception) { MessageBox.Show("There was a problem saving the file." + "Check the file permissions."); } }
private: void Button5_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ ) { try { if ( image1 != nullptr ) { image1->Save( "c:\\myBitmap.bmp" ); Button5->Text = "Saved file."; } } catch ( Exception^ ) { MessageBox::Show( "There was a problem saving the file." "Check the file permissions." ); } }
private void button5_Click(Object sender, System.EventArgs e) { try { if (image1 != null) { image1.Save("c:\\myBitmap.bmp"); button5.set_Text("Saved file."); } } catch (System.Exception exp) { MessageBox.Show(("There was a problem saving the file." + "Check the file permissions.")); } } //button5_Click

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Image.Save メソッド (Stream, ImageFormat)
アセンブリ: System.Drawing (system.drawing.dll 内)




Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Image.Save メソッド (Stream, ImageCodecInfo, EncoderParameters)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub Save ( _ stream As Stream, _ encoder As ImageCodecInfo, _ encoderParams As EncoderParameters _ )
Dim instance As Image Dim stream As Stream Dim encoder As ImageCodecInfo Dim encoderParams As EncoderParameters instance.Save(stream, encoder, encoderParams)
public function Save ( stream : Stream, encoder : ImageCodecInfo, encoderParams : EncoderParameters )



Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Image.Save メソッド

名前 | 説明 |
---|---|
Image.Save (String) | この Image を指定したファイルまたはストリームに保存します。 |
Image.Save (Stream, ImageFormat) | このイメージを、指定した形式で指定したストリームに保存します。 .NET Compact Framework によってサポートされています。 |
Image.Save (String, ImageFormat) | この Image を、指定した形式で指定したファイルに保存します。 .NET Compact Framework によってサポートされています。 |
Image.Save (Stream, ImageCodecInfo, EncoderParameters) | 指定したエンコーダ パラメータおよびイメージ エンコーダ パラメータを使用して、このイメージを指定したストリームに保存します。 |
Image.Save (String, ImageCodecInfo, EncoderParameters) | 指定したエンコーダ パラメータおよびイメージ エンコーダ パラメータを使用して、指定したファイルにこの Image を保存します。 |

Image.Save メソッド (String, ImageCodecInfo, EncoderParameters)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub Save ( _ filename As String, _ encoder As ImageCodecInfo, _ encoderParams As EncoderParameters _ )
Dim instance As Image Dim filename As String Dim encoder As ImageCodecInfo Dim encoderParams As EncoderParameters instance.Save(filename, encoder, encoderParams)
public function Save ( filename : String, encoder : ImageCodecInfo, encoderParams : EncoderParameters )



Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Image.Saveのページへのリンク