在C#中如何实现几种图片格式的转换

本人新手请教高手们如何用C#代码实现这几种格式的转换:DDS转换成JPG、TGA转换成JPG、JPG转换成TGA、DDS转换成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();
}
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-08-16
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);
}
}
}
    }

第2个回答  2010-09-06
图片格式转换.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本回答被网友采纳
第3个回答  2010-09-06
截取字符串吧! 比如你图片是hao.jpg 那么就截取.后面的字符

后面是jpg 那么就用TGA来替换!

到网上查一下 怎么截取字符串吧! 不会再HI 我
相似回答