我用C#写了个上传图片的页面,需要对图片按照规定尺寸进行缩放,保存缩放后的图片。上传Gif时,出错: Stream upImageStream = ImageUpload.InputStream;//上传文件流 System.Drawing.Image orgImg = System.Drawing.Image.FromStream(upImageStream);//通过文件流获取原始图片
Bitmap zoomImg = new Bitmap(orgImg.Width, orgImg.Height, orgImg.PixelFormat);//创建图片(位图
Graphics myImg = Graphics.FromImage(zoomImg);//创建Graphics
在最后一句出现问题(处理GIF 图片时候,提示无法从带有索引像素格式的图像创建 Graphics),老提示:A Graphics object cannot be created from an image that has an indexed pixel format.请问如何解决,谢谢!!我用的vs 2005 Express Edition
Bitmap zoomImg = new Bitmap(orgImg.Width, orgImg.Height, orgImg.PixelFormat);//创建图片(位图
Graphics myImg = Graphics.FromImage(zoomImg);//创建Graphics
在最后一句出现问题(处理GIF 图片时候,提示无法从带有索引像素格式的图像创建 Graphics),老提示:A Graphics object cannot be created from an image that has an indexed pixel format.请问如何解决,谢谢!!我用的vs 2005 Express Edition
http://www.codeproject.com/csharp/water.asp
分解合成gif,参看
http://www.andreas.com/faq-gif-png.html
http://www.codeproject.com/useritems/Extract_Animated_Gif_NET.asp
http://www.codeproject.com/dotnet/NGif.asp
还是没有解决问题。
Graphics myImg = Graphics.FromImage(zoomImg);//创建Graphics
在最后一句出现问题(处理GIF 图片时候,提示无法从带有索引像素格式的图像创建 Graphics),老提示:A Graphics object cannot be created from an
1、gif 分解成png或者jpg文件组;
2、对每个png或者jpg文件进行处理;
3、把处理好的png或者jpg文件组,进行合成一个gif。
http://www.codeproject.com/useritems/Extract_Animated_Gif_NET.asp
这个实例在C#中你调试过吗?
我调试的时候出现错误:
Bitmap b = new Bitmap((Bitmap)myImg.SelectActiveFrame(ImgFrmDim, 0));就是这句,错误提示。
Error 1 Cannot convert type 'int' to 'System.Drawing.Bitmap'。能解释一下吗?谢谢!
我查了一下msdn,myImg.SelectActiveFrame(ImgFrmDim, 0)的返回值就是0.那gif 分解成png或者jpg文件组如何进行。谢谢
Image myImg = Image.FromFile(@"d:\test.gif");
//Create a new FrameDimension object from this image
System.Drawing.Imaging.FrameDimension ImgFrmDim = new System.Drawing.Imaging.FrameDimension( myImg.FrameDimensionsList[0]);
//Determine the number of frames in the image
//Note that all images contain at least 1 frame, but an animated GIF will contain more than 1 frame.
int nooffrm = myImg.GetFrameCount( ImgFrmDim );for( int i = 0; i < nooffrm; i++ )
{
myImg.SelectActiveFrame( ImgFrmDim, i );
myImg.Save( string.Format( @"d:\Frame{0}.jpg", i ), ImageFormat.Jpeg );
}
表示感谢!