您现在的位置: 网页制作教程网 >> 网络编程 >> Asp.net 教程 >> ASP.NET 开发技巧 >> 文章正文
作者:AspCool
来源:ASPCool
热度:
2006-10-21 13:14:38
| 以下是引用片段: Dim fs As FileStream = CType(saveFileDialog1.OpenFile(), FileStream) ' Save the Image in the appropriate ImageFormat based upon the ' file type selected in the dialog box. ' NOTE that the FilterIndex property is one-based. Select Case saveFileDialog1.FilterIndex Case 1 Me.button2.Image.Save(fs, ImageFormat.Jpeg) Case 2 Me.button2.Image.Save(fs, ImageFormat.Bmp) Case 3 Me.button2.Image.Save(fs, ImageFormat.Gif) End Select fs.Close() End If End Sub // C# // NOTE: You must import the following namespaces: // using System.IO; // using System.Drawing.Imaging; // Without these import statements at the beginning of your code, // the code example will not function. private void button2_Click(object sender, System.EventArgs e) { // Display an SaveFileDialog so the user can save the Image // assigned to Button2. SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "JPeg Image*.jpgBitmap Image*.bmpGif Image*.gif"; saveFileDialog1.Title = "Save an Image File"; saveFileDialog1.ShowDialog(); // If the file name is not an empty string open it for saving. if(saveFileDialog1.FileName != "") { // Save the Image via a FileStream created by the OpenFile method. FileStream fs = (FileStream)saveFileDialog1.OpenFile(); // Save the Image in the appropriate ImageFormat based upon the // File type selected in the dialog box. // NOTE that the FilterIndex property is one-based. switch(saveFileDialog1.FilterIndex) { case 1 : this.button2.Image.Save(fs,ImageFormat.Jpeg); break; case 2 : this.button2.Image.Save(fs,ImageFormat.Bmp); break; case 3 : this.button2.Image.Save(fs,ImageFormat.Gif); break; } fs.Close(); } } |
关于写入文件流的进一步信息,请参阅 FileStream.BeginWrite 方法。
我来说两句:
推荐文章
相关文章