none
What does this constructor do?

    Question

  • public Bitmap (Image original, Size newSize)

     

    Is it downsampling, if it is which algorithm (interpolation mode) is used or it is just through away the rest of pixels

    Tuesday, April 29, 2008 2:37 PM

Answers

  • The Graphics and Bitmap classes internally rely on the GDI+ APIs, for more details, I suggest that you can use .NET Reflector to check the implementation of the “BitMap” class.

    This should be able to get you started.

    Thanks!

    Wednesday, April 30, 2008 10:07 AM
  • The interpolation mode is controlled by Graphics.InterpolationMode.  When you use this Bitmap constructor, you don't get to control the mode.  The Graphics object used inside the constructor is out of reach.  Do it like this:

          using (Bitmap srce = new Bitmap(@"c:\temp\test1.bmp"))
          using (Bitmap dest = new Bitmap(srce.Width / 2, srce.Height / 2, srce.PixelFormat))
          using (Graphics gr = Graphics.FromImage(dest)) {
            gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
            gr.DrawImage(srce, 0, 0, dest.Width, dest.Height);
            dest.Save(@"c:\temp\test2.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
          }
    Wednesday, April 30, 2008 11:48 AM
    Moderator

All replies

  • public Bitmap(System.Drawing.Image original, System.Drawing.Size newSize)

    Member of System.Drawing.Bitmap

    Summary:

    Initializes a new instance of the System.Drawing.Bitmap class from the specified existing image and with the specified size.

    Parameters:

    original: The System.Drawing.Image from which to create the new System.Drawing.Bitmap.

    newSize: The System.Drawing.Size structure that represent the size of the new System.Drawing.Bitmap.

    Exceptions:

    System.Exception: The operation failed.

     

    No idea which algorithm is used.  Does the method do what you need?

    Tuesday, April 29, 2008 4:33 PM
  • The Graphics and Bitmap classes internally rely on the GDI+ APIs, for more details, I suggest that you can use .NET Reflector to check the implementation of the “BitMap” class.

    This should be able to get you started.

    Thanks!

    Wednesday, April 30, 2008 10:07 AM
  • The interpolation mode is controlled by Graphics.InterpolationMode.  When you use this Bitmap constructor, you don't get to control the mode.  The Graphics object used inside the constructor is out of reach.  Do it like this:

          using (Bitmap srce = new Bitmap(@"c:\temp\test1.bmp"))
          using (Bitmap dest = new Bitmap(srce.Width / 2, srce.Height / 2, srce.PixelFormat))
          using (Graphics gr = Graphics.FromImage(dest)) {
            gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
            gr.DrawImage(srce, 0, 0, dest.Width, dest.Height);
            dest.Save(@"c:\temp\test2.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
          }
    Wednesday, April 30, 2008 11:48 AM
    Moderator
  • Actually that exactly what I did

     

    but I wanted to reuse the code of the Bitmap

    Also (in case u are reader from google).  Don't forget to downsample with repecting the aspect ratio of original bitmap.

     

    the method without saving seems to be a performance hit, since you are creating another empty bitmap with the size you want and then draw on it. and who knows maybe you want to save it.  it might take more than 1 MS for images more than 2 MPixels.

     

    Thanks

     

     

    Monday, May 05, 2008 5:37 AM
  • Good Link NoBug

    Thanks

     

    Monday, May 05, 2008 5:39 AM