一个小程序,可以用来转换图片的格式,比如将GIF格式转换成JPEG
#pragma once
namespace 图片格式转换器 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Form1 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
/// 与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。否则,
/// 设计器将不能与此窗体的关联
/// 本地化资源正确交互。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::GroupBox^ groupBox1;
private: System::Windows::Forms::RadioButton^ radioButton6;
private: System::Windows::Forms::RadioButton^ radioButton5;
private: System::Windows::Forms::RadioButton^ radioButton4;
private: System::Windows::Forms::RadioButton^ radioButton3;
private: System::Windows::Forms::RadioButton^ radioButton2;
private: System::Windows::Forms::RadioButton^ radioButton1;
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->radioButton6 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton5 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton4 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton3 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->groupBox1->SuspendLayout();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->BackColor = System::Drawing::SystemColors::ActiveCaptionText;
this->pictureBox1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.BackgroundImage")));
this->pictureBox1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
this->pictureBox1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
this->pictureBox1->Cursor = System::Windows::Forms::Cursors::Cross;
this->pictureBox1->Location = System::Drawing::Point(12, 29);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(455, 366);
this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location = System::Drawing::Point(492, 29);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(69, 24);
this->button1->TabIndex = 1;
this->button1->Text = L"浏览";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(492, 71);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(69, 23);
this->button2->TabIndex = 2;
this->button2->Text = L"保存";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// groupBox1
//
this->groupBox1->Controls->Add(this->radioButton6);
this->groupBox1->Controls->Add(this->radioButton5);
this->groupBox1->Controls->Add(this->radioButton4);
this->groupBox1->Controls->Add(this->radioButton3);
this->groupBox1->Controls->Add(this->radioButton2);
this->groupBox1->Controls->Add(this->radioButton1);
this->groupBox1->Location = System::Drawing::Point(492, 155);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(85, 240);
this->groupBox1->TabIndex = 3;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"图片格式";
//
// radioButton6
//
this->radioButton6->AutoSize = true;
this->radioButton6->Location = System::Drawing::Point(6, 198);
this->radioButton6->Name = L"radioButton6";
this->radioButton6->Size = System::Drawing::Size(65, 16);
this->radioButton6->TabIndex = 6;
this->radioButton6->TabStop = true;
this->radioButton6->Text = L"Wmf格式";
this->radioButton6->UseVisualStyleBackColor = true;
//
// radioButton5
//
this->radioButton5->AutoSize = true;
this->radioButton5->Location = System::Drawing::Point(6, 163);
this->radioButton5->Name = L"radioButton5";
this->radioButton5->Size = System::Drawing::Size(71, 16);
this->radioButton5->TabIndex = 5;
this->radioButton5->TabStop = true;
this->radioButton5->Text = L"Tiff格式";
this->radioButton5->UseVisualStyleBackColor = true;
//
// radioButton4
//
this->radioButton4->AutoSize = true;
this->radioButton4->Location = System::Drawing::Point(6, 129);
this->radioButton4->Name = L"radioButton4";
this->radioButton4->Size = System::Drawing::Size(65, 16);
this->radioButton4->TabIndex = 4;
this->radioButton4->TabStop = true;
this->radioButton4->Text = L"Png格式";
this->radioButton4->UseVisualStyleBackColor = true;
//
// radioButton3
//
this->radioButton3->AutoSize = true;
this->radioButton3->Location = System::Drawing::Point(6, 94);
this->radioButton3->Name = L"radioButton3";
this->radioButton3->Size = System::Drawing::Size(71, 16);
this->radioButton3->TabIndex = 3;
this->radioButton3->TabStop = true;
this->radioButton3->Text = L"Jpeg格式";
this->radioButton3->UseVisualStyleBackColor = true;
//
// radioButton2
//
this->radioButton2->AutoSize = true;
this->radioButton2->Location = System::Drawing::Point(6, 61);
this->radioButton2->Name = L"radioButton2";
this->radioButton2->Size = System::Drawing::Size(65, 16);
this->radioButton2->TabIndex = 2;
this->radioButton2->TabStop = true;
this->radioButton2->Text = L"Gif格式";
this->radioButton2->UseVisualStyleBackColor = true;
//
// radioButton1
//
this->radioButton1->AutoSize = true;
this->radioButton1->Location = System::Drawing::Point(6, 30);
this->radioButton1->Name = L"radioButton1";
this->radioButton1->Size = System::Drawing::Size(65, 16);
this->radioButton1->TabIndex = 1;
this->radioButton1->TabStop = true;
this->radioButton1->Text = L"Bmp格式";
this->radioButton1->UseVisualStyleBackColor = true;
//
// openFileDialog1
//
this->openFileDialog1->FileName = L"openFileDialog1";
this->openFileDialog1->Filter = resources->GetString(L"openFileDialog1.Filter");
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::InactiveCaptionText;
this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
this->ClientSize = System::Drawing::Size(589, 463);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"图片格式转换器";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if(this->openFileDialog1->ShowDialog()==System::Windows::Forms::DialogResult::Cancel)return;
try{
this->pictureBox1->Image=System::Drawing::Bitmap::FromFile(this->openFileDialog1->FileName);
}catch(Exception ^e){
MessageBox::Show("打开图像文件错误!","信息提示",MessageBoxButtons::OK,MessageBoxIcon::Information);
}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
if(this->saveFileDialog1->ShowDialog()==System::Windows::Forms::DialogResult::Cancel)
return;
String^ MyFileName=this->saveFileDialog1->FileName;
try
{
if(this->radioButton1->Checked)
{
this->pictureBox1->Image->Save(String::Concat(MyFileName,".bmp"),System::Drawing::Imaging::ImageFormat::Bmp);
}
if(this->radioButton2->Checked)
{
this->pictureBox1->Image->Save(String::Concat(MyFileName,".gif"),System::Drawing::Imaging::ImageFormat::Gif);
}
if(this->radioButton3->Checked)
{
this->pictureBox1->Image->Save(String::Concat(MyFileName,".jpg"),System::Drawing::Imaging::ImageFormat::Jpeg);
}
if(this->radioButton4->Checked)
{
this->pictureBox1->Image->Save(String::Concat(MyFileName,".png"),System::Drawing::Imaging::ImageFormat::Png);
}
if(this->radioButton5->Checked)
{
this->pictureBox1->Image->Save(String::Concat(MyFileName,".tif"),System::Drawing::Imaging::ImageFormat::Tiff);
}
if(this->radioButton6->Checked)
{
this->pictureBox1->Image->Save(String::Concat(MyFileName,".wmf"),System::Drawing::Imaging::ImageFormat::Wmf);
}
}
catch(Exception^ Error)
{
MessageBox::Show("保存图像文件时发生错误!","信息提示",MessageBoxButtons::OK,MessageBoxIcon::Information);
}
}
};
}