title: Convert IFormFile to Image in Asp Core
body: <p>i need to resize file upload if file is image . </p>
  
  <p>i write the extention for resize that :</p>
  
  <pre><code> public static Image ResizeImage(this Image image, int width, int height)
      {
          var res = new Bitmap(width, height);
          using (var graphic = Graphics.FromImage(res))
          {
              graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
              graphic.SmoothingMode = SmoothingMode.HighQuality;
              graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
              graphic.CompositingQuality = CompositingQuality.HighQuality;
              graphic.DrawImage(image, 0, 0, width, height);
          }
          return res;
      }
  </code></pre>
  
  <p>and this is <code>Upload Action :</code></p>
  
  <pre><code> [HttpPost("UploadNewsPic"), DisableRequestSizeLimit]
      public IActionResult UploadNewsPic(IFormFile file)
      {
          if (file.IsImage())
          {
  
          }
          try
          {
              if (file.Length &gt; 0)
              {
                  string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                  string fullPath = Path.Combine(_applicationRoot.UploadNewPath(), file.Name);
                  using (var stream = new FileStream(fullPath, FileMode.Create))
                  {
                      file.CopyTo(stream);
                  }
              }
              return Ok();
          }
          catch (Exception e)
          {
              return BadRequest();
          }
      }
  </code></pre>
  
  <p><strong>now my problem is here =></strong> my extention just work on type of <code>Image</code> file but type of this file is <code>IFormFile</code> . how can i convert the <code>IFormFile</code> to <code>Image</code> type ?</p>