Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在不丢失右下像素部分的情况下,用c#调整图像大小_C#_Image_Graphics_Resize - Fatal编程技术网

在不丢失右下像素部分的情况下,用c#调整图像大小

在不丢失右下像素部分的情况下,用c#调整图像大小,c#,image,graphics,resize,C#,Image,Graphics,Resize,我有一个c类,大致如下: class ImageContainer { Image image; internal ImageContainer getResized(int width, int height) { Bitmap bmp = new Bitmap(width, height); //Create a System.Drawing.Graphics object from the Bitmap which we will use to draw the

我有一个c类,大致如下:

 class ImageContainer
 {
  Image image;
  internal ImageContainer getResized(int width, int height)
  {
   Bitmap bmp = new Bitmap(width, height);
   //Create a System.Drawing.Graphics object from the Bitmap which we will use to draw the high quality scaled image
   System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp);
   //Set the System.Drawing.Graphics object property SmoothingMode to HighQuality
   gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
   //Set the System.Drawing.Graphics object property CompositingQuality to HighQuality
   gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
   //Set the System.Drawing.Graphics object property InterpolationMode to High
   gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
   //Draw the original image into the target Graphics object scaling to the desired width and height
   System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, width, height);
   gr.DrawImage(image, rectDestination, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
   //dispose / release  resources

   ImageContainer ic = new ImageContainer();
   ic.image = bmp;

   return ic;
  }
 }

调整大小效果很好,但在缩小图像时,DrawImage不会绘制最右边和较低的像素碎片。

通过

gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
:)