如题,用Graphics.DrawImage 切图,就是截取一个图片上指定部分的图片draw到另一个图片上,gif失真,请前辈们指教啊,

解决方案 »

  1.   

    我不缩放啊,生成图片部分的代码
    using (System.Drawing.Image oImg = System.Drawing.Image.FromFile(sImagePath))
                {
                    //创建图片
                    System.Drawing.Bitmap oBit = new System.Drawing.Bitmap(iPartWidth, iPartHeight);
                    System.Drawing.Graphics oPic = System.Drawing.Graphics.FromImage(oBit);
                    //目标位置
                    System.Drawing.Rectangle rDest = new System.Drawing.Rectangle(
                        new System.Drawing.Point(iPartStartPointX, iPartStartPointY),
                        new System.Drawing.Size(iPartWidth, iPartHeight));
                    //原图位置(默认从原图中截取的图片大小等于目标图片的大小)
                    System.Drawing.Rectangle rOrig = new System.Drawing.Rectangle(
                        new System.Drawing.Point(iOrigStartPointX, iOrigStartPointY),
                        new System.Drawing.Size(iPartWidth, iPartHeight));
                    //生成图片
                    System.Drawing.Brush bh = new System.Drawing.SolidBrush(System.Drawing.Color.White);
                    oPic.FillRectangle(bh, rDest);
                    oPic.DrawImage(oImg, rDest, rOrig, System.Drawing.GraphicsUnit.Pixel);
                    oImg.Dispose();
                    //检查文件
                    if (System.IO.File.Exists(sPath))
                    {
                        System.IO.File.SetAttributes(sPath, System.IO.FileAttributes.Normal);
                        System.IO.File.Delete(sPath);
                    }
                    //保存文件
                    switch (sCode.ToLower())
                    {
                        case ".gif": oBit.Save(sPath, System.Drawing.Imaging.ImageFormat.Gif); break;
                        case ".png": oBit.Save(sPath, System.Drawing.Imaging.ImageFormat.Png); break;
                        case ".bmp": oBit.Save(sPath, System.Drawing.Imaging.ImageFormat.Bmp); break;
                        default: oBit.Save(sPath, System.Drawing.Imaging.ImageFormat.Jpeg); break;
                    }
                }