using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Imaging;
namespace imageConvert
{
public class Form1 : System.Windows.Forms.Form
{
private Bitmap m_bitmap; //重要!打开的图象文件放在这个实例中
private int m_width0; //图象的宽度
private int m_height0; //图象的高度
private System.Windows.Forms.PictureBox pictureBox1;
private void btnOpenfile_Click(object sender, System.EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = cmbOpenFiletype.Text + "|" + cmbOpenFiletype.Text;
string filter = ofd.Filter;
ofd.InitialDirectory = System.Environment.CurrentDirectory;
ofd.Title = "打开图象文件";
ofd.ShowHelp = true;
if(ofd.ShowDialog() == DialogResult.OK)
{
string strFileName = ofd.FileName;
m_bitmap = new Bitmap(strFileName);
if(m_bitmap.Width > m_bitmap.Height)
{
//Keep the width
pictureBox1.Width = m_width0;
pictureBox1.Height = (int)((double)m_bitmap.Height*m_width0/m_bitmap.Width);
}
else
{
//Keep the height
pictureBox1.Height = m_height0;
pictureBox1.Width = (int)((double)m_bitmap.Width*m_height0/m_bitmap.Height);
}
pictureBox1.Image = m_bitmap;
btnSave.Enabled = true;
}
}
private void btnSave_Click(object sender, System.EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "图象另存为";
sfd.OverwritePrompt = true;
sfd.CheckPathExists = true;
sfd.Filter = cmbSaveFiletype.Text + "|" + cmbSaveFiletype.Text;
sfd.ShowHelp = true;
if(sfd.ShowDialog() == DialogResult.OK)
{
string strFileName = sfd.FileName;
switch(cmbSaveFiletype.Text)
{
case "*.bmp":
m_bitmap.Save(strFileName, ImageFormat.Bmp);
break;
case "*.jpg":
m_bitmap.Save(strFileName, ImageFormat.Jpeg);
break;
case "*.gif":
m_bitmap.Save(strFileName, ImageFormat.Gif);
break;
case "*.ico":
m_bitmap.Save(strFileName, ImageFormat.Icon);
break;
}
MessageBox.Show("图象文件格式转换成功!", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
}
分享到:
相关推荐
易语言使用GDI+在内存转换图像格式源码,使用GDI+在内存转换图像格式,转换图像格式,A2W,GdiplusStartup,GdiplusShutdown,MultiByteToWideChar,GdipLoadImageFromFile,GdipSaveImageToFile,CLSIDFromString,...
易语言转换图像格式模块源码,转换图像格式模块,A2W,销毁,载入图像,载入文件,转换到字节集,转换到文件,取图片宽度,取图片高度,取图片尺寸,GetCLSID,GdiplusStartup,GdiplusShutdown,MultiByteToWideChar,...
图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换图片格式转换
图像格式转换算法原理,文章分析了各个图像格式,并提出了转换方式
各种图片格式转换vc实现
易语言图片格式转换源码,图片格式转换,转换图像格式,A2W,GdiplusStartup,GdiplusShutdown,MultiByteToWideChar,GdipLoadImageFromFile,GdipSaveImageToFile,CLSIDFromString,GdipDisposeImage
批量转换图像格式和尺寸的MATLAB源代码
易语言源码易语言转换图像格式模块源码.rar 易语言源码易语言转换图像格式模块源码.rar 易语言源码易语言转换图像格式模块源码.rar 易语言源码易语言转换图像格式模块源码.rar 易语言源码易语言转换图像格式模块...
图片格式转换 压缩 图片格式转换 压缩 图片格式转换 压缩 图片格式转换 压缩 图片格式转换 压缩 图片格式转换 压缩 图片格式转换 压缩 图片格式转换 压缩 图片格式转换 压缩 图片格式转换 压缩 图片格式转换 压缩 ...
图像格式转换;图像格式转换;图像格式转换;图像格式转换;图像格式转换;图像格式转换;图像格式转换;图像格式转换
批量转换图片格式的工具,可以转换png、jpg、gif、bmp、ico格式。 选择图片suo所在文件夹,选择要转换的格式,转换后,打开文件夹就可以看到转换后的图片。
在linux环境下进行bmp图像转换yuv格式
3dmax转换图片格式
使用GDIPlus实现图像格式转换。支持转换文件、支持内存中转换。支持BMP、JPG、GIF、TIFF、PNG格式。作者:凌晨孤星。修改:邓学彬(泪闯天涯)。作者:凌晨孤星。修改:邓学彬(泪闯天涯)。资源作者:。凌晨孤星。资源...
批量转换图像格式,自定义像素无损压缩,图像信息读取,支持GPS地理位置
好东西 转换图像格式c#源代码
增加填充图片背景颜色的功能,以免在透明PNG转换为JPG时出现黑色背景。
图像格式转换程序 图像格式转换程序 图像格式转换程序
mapgis格式与cad格式、shp格式相互转换图片格式转换为msi.doc