在C#中如何实现几种图片格式的转换
本人新手请教高手们如何用C#代码实现这几种格式的转换:DDS转换成JPG、TGA转换成JPG、JPG转换成TGA、DDS转换成TGA。求详细代码,求高手指点一下高手都哪里...
本人新手请教高手们如何用C#代码实现这几种格式的转换:DDS转换成JPG、TGA转换成JPG、JPG转换成TGA、DDS转换成TGA。求详细代码,求高手指点一下
高手都哪里去了啊 就没有一个人能把JPG转换成TGA吗,高手啊 快来吧 很急的啊 展开
高手都哪里去了啊 就没有一个人能把JPG转换成TGA吗,高手啊 快来吧 很急的啊 展开
展开全部
这个是一个源代码,你参考一下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
namespace convert
{
public partial class Form1 : Form
{
Bitmap bitmap;
public Form1()
{
InitializeComponent();
}
private void buttonOpen_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "*.bmp|*.bmp";
openFileDialog.Title = "打开图像文件";
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (bitmap != null)
{
bitmap.Dispose();
}
string fileName = openFileDialog.FileName;
bitmap = new Bitmap(fileName);
if (bitmap.Width > bitmap.Height)
{
pictureBox.Width = panel2.Width;
pictureBox.Height = (int)((double)bitmap.Height * panel2.Width / bitmap.Width);
}
else
{
pictureBox.Height = panel2.Height;
pictureBox.Width = (int)((double)bitmap.Width * panel2.Height / bitmap.Height);
}
pictureBox.Image = bitmap;
FileInfo f = new FileInfo(fileName);
this.Text = "图像转换:" + f.Name;
this.label1.Text = f.Name;
buttonConvert.Enabled = true;
}
}
private void buttonConvert_Click(object sender, EventArgs e)
{
if (comboBox.SelectedItem == null)
{
return;
}
else
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "转化为:";
saveFileDialog.OverwritePrompt = true;
saveFileDialog.CheckPathExists = true;
saveFileDialog.Filter = comboBox.Text + "|" + comboBox.Text;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = saveFileDialog.FileName;
bitmap.Save(fileName, ImageFormat.Jpeg);
FileInfo f = new FileInfo(fileName);
this.Text = "图像转换:" + f.Name;
label1.Text = f.Name;
}
}
}
private void panel2_Resize(object sender, EventArgs e)
{
pictureBox.Top = panel1.Top;
pictureBox.Left = panel1.Left;
if (bitmap != null)
{
if (bitmap.Width > bitmap.Height)
{
pictureBox.Width = panel2.Width;
pictureBox.Height = (int)((double)bitmap.Height * panel2.Width / bitmap.Width);
}
else
{
pictureBox.Height = panel2.Height;
pictureBox.Width = (int)((double)bitmap.Width * panel2.Height / bitmap.Height);
}
}
else
{
pictureBox.Width = panel2.Width;
pictureBox.Height = panel2.Height;
}
pictureBox.Refresh();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
namespace convert
{
public partial class Form1 : Form
{
Bitmap bitmap;
public Form1()
{
InitializeComponent();
}
private void buttonOpen_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "*.bmp|*.bmp";
openFileDialog.Title = "打开图像文件";
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (bitmap != null)
{
bitmap.Dispose();
}
string fileName = openFileDialog.FileName;
bitmap = new Bitmap(fileName);
if (bitmap.Width > bitmap.Height)
{
pictureBox.Width = panel2.Width;
pictureBox.Height = (int)((double)bitmap.Height * panel2.Width / bitmap.Width);
}
else
{
pictureBox.Height = panel2.Height;
pictureBox.Width = (int)((double)bitmap.Width * panel2.Height / bitmap.Height);
}
pictureBox.Image = bitmap;
FileInfo f = new FileInfo(fileName);
this.Text = "图像转换:" + f.Name;
this.label1.Text = f.Name;
buttonConvert.Enabled = true;
}
}
private void buttonConvert_Click(object sender, EventArgs e)
{
if (comboBox.SelectedItem == null)
{
return;
}
else
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "转化为:";
saveFileDialog.OverwritePrompt = true;
saveFileDialog.CheckPathExists = true;
saveFileDialog.Filter = comboBox.Text + "|" + comboBox.Text;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = saveFileDialog.FileName;
bitmap.Save(fileName, ImageFormat.Jpeg);
FileInfo f = new FileInfo(fileName);
this.Text = "图像转换:" + f.Name;
label1.Text = f.Name;
}
}
}
private void panel2_Resize(object sender, EventArgs e)
{
pictureBox.Top = panel1.Top;
pictureBox.Left = panel1.Left;
if (bitmap != null)
{
if (bitmap.Width > bitmap.Height)
{
pictureBox.Width = panel2.Width;
pictureBox.Height = (int)((double)bitmap.Height * panel2.Width / bitmap.Width);
}
else
{
pictureBox.Height = panel2.Height;
pictureBox.Width = (int)((double)bitmap.Width * panel2.Height / bitmap.Height);
}
}
else
{
pictureBox.Width = panel2.Width;
pictureBox.Height = panel2.Height;
}
pictureBox.Refresh();
}
}
}
展开全部
private void ZhuangHuan(string sourcePath,string desPath)
{
using(Bitmap bitmap=new Bitmap(sourcePath))
{
using(Bitmap newBitmap=bitmap.Clone(new Rectangle(0,0,bitmap.Width,bitmap.Height),PixelFormat.Format24bppRgb))
{
using(Icon icon=Icon.FromHandle(newBitmap.GetHicon()))
{
FileStream fileStream = new FileStream(desPath, System.IO.FileMode.Create);
icon.Save(fileStream);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
图片格式转换.net framework基本不提供,具体实现是算法问题,估计也不是你想要的,推荐两个C#图片处理库(其实都是本地库的C#封装:)推荐第一个:
1、http://openil.sourceforge.net/
C#封装:
http://www.mastropaolo.com/devildotnet/
2、http://freeimage.sourceforge.net/index.html
C#封装:http://www.codeproject.com/KB/graphics/freeimagecswrapper.aspx?msg=1203554
1、http://openil.sourceforge.net/
C#封装:
http://www.mastropaolo.com/devildotnet/
2、http://freeimage.sourceforge.net/index.html
C#封装:http://www.codeproject.com/KB/graphics/freeimagecswrapper.aspx?msg=1203554
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
截取字符串吧! 比如你图片是hao.jpg 那么就截取.后面的字符
后面是jpg 那么就用TGA来替换!
到网上查一下 怎么截取字符串吧! 不会再HI 我
后面是jpg 那么就用TGA来替换!
到网上查一下 怎么截取字符串吧! 不会再HI 我
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询