提供一个方案: 你可以先创建一个BitMap,如: Bitmap bmp = new Bitmap(宽, 高,色素[PixelFormat枚举]); 然后使用Graphics g = Graphics.FromImage(bmp); 使用g.DrawImage();g.Save();把图像绘制出来; 最后用bmp.Save(文件名,图片格式[ImageFormat枚举]); 就可以实现图片的转换.
tks any other detail to help me ?
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Bitmap bmp = new Bitmap(320, 240, System.Drawing.Imaging.PixelFormat.Format16bppRgb555);//用宽/高/色度创建Bitmap对象. Graphics g = Graphics.FromImage(bmp); g.DrawImage(new Bitmap("源文件的位置"), new Point(0, 0)); g.Save(); bmp.Save("新保存文件的位置", System.Drawing.Imaging.ImageFormat.Bmp);//指定新图片保存位置和格式. } } }
非常感谢。 就以上代码问几个问题,不好意思有点懒 1、 Graphics g = Graphics.FromImage(bmp); g.DrawImage(new Bitmap("源文件的位置"), new Point(0, 0)); 这样是不是只能从BMP格式的图片转成其他的图片,这个源格式是取决于DRAWIMGAGE方法时读进去的图片格式,还是取决与BITMAP构造函数?不好意思。 2、另外如果图片是从WEB上传上来,我读到该图片时还没存放到硬盘上时,这个图片能否直接传递给BITMAP对象? 3、如果上传上来的图片后缀名和实际的格式不对时,我有没有办法不根据后缀名去判断其真实的图片格式?非常感谢您的帮助。
你可以先创建一个BitMap,如:
Bitmap bmp = new Bitmap(宽, 高,色素[PixelFormat枚举]);
然后使用Graphics g = Graphics.FromImage(bmp);
使用g.DrawImage();g.Save();把图像绘制出来;
最后用bmp.Save(文件名,图片格式[ImageFormat枚举]);
就可以实现图片的转换.
any other detail to help me ?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(320, 240, System.Drawing.Imaging.PixelFormat.Format16bppRgb555);//用宽/高/色度创建Bitmap对象.
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(new Bitmap("源文件的位置"), new Point(0, 0));
g.Save();
bmp.Save("新保存文件的位置", System.Drawing.Imaging.ImageFormat.Bmp);//指定新图片保存位置和格式. }
}
}
就以上代码问几个问题,不好意思有点懒
1、 Graphics g = Graphics.FromImage(bmp);
g.DrawImage(new Bitmap("源文件的位置"), new Point(0, 0));
这样是不是只能从BMP格式的图片转成其他的图片,这个源格式是取决于DRAWIMGAGE方法时读进去的图片格式,还是取决与BITMAP构造函数?不好意思。
2、另外如果图片是从WEB上传上来,我读到该图片时还没存放到硬盘上时,这个图片能否直接传递给BITMAP对象?
3、如果上传上来的图片后缀名和实际的格式不对时,我有没有办法不根据后缀名去判断其真实的图片格式?非常感谢您的帮助。
2.如果是WEB上传文件可以考虑使用Bitmap(Stream stream)这个重载.
3.没试过.