Why I'm getting the exception: "System.Drawing.SafeNativeMethods+Gdip.CheckStatus(int status)" when running the app?

Viewed 612

I'm using a method named: Image_resize to resizing my images, but when I call this method, I get:

ArgumentException: Parameter is not valid. System.Drawing.SafeNativeMethods+Gdip.CheckStatus(int status)

Stack Query Cookies Headers Routing ArgumentException: Parameter is not valid. System.Drawing.SafeNativeMethods+Gdip.CheckStatus(int status) System.Drawing.Bitmap..ctor(string filename, bool useIcm) System.Drawing.Bitmap..ctor(string filename) Keyhanatr.Core.ImageMethods.ImageConvertor.Image_resize(string input_Image_Path, string output_Image_Path, int new_Width) in ImgMehods.cs + Bitmap source_Bitmap = new Bitmap(input_Image_Path); Keyhanatr.Core.ImageMethods.ImgMehods.CreateProductImg(IFormFile imgUp) in ImgMehods.cs + ImageConvertor.Image_resize(imgPath,thumbPath,150); Keyhanatr.Core.Services.Products.ProductServices.AddProduct(Product product, IFormFile imgUp) in ProductServices.cs + product.ImageName = ImgMehods.CreateProductImg(imgUp); Keyhanatr.Areas.Admin.Controllers.ProductsController.Create(Product product, IFormFile imgUp) in ProductsController.cs + _productServices.AddProduct(product, imgUp);

Also getting green squiggle under some lines. The used method is as fallowing :

public static class ImageConvertor
{
    public static void Image_resize(string input_Image_Path, string output_Image_Path, int new_Width)
    {
        const long quality = 50L;
        Bitmap source_Bitmap = new Bitmap(input_Image_Path);
        double dblWidth_origial = source_Bitmap.Width;
        double dblHeigth_origial = source_Bitmap.Height;
        double relation_heigth_width = dblHeigth_origial / dblWidth_origial;
        int new_Height = (int)(new_Width * relation_heigth_width);

        //< create Empty Drawarea >
        var new_DrawArea = new Bitmap(new_Width, new_Height);
        //</ create Empty Drawarea >

        using (var graphic_of_DrawArea = Graphics.FromImage(new_DrawArea))
        {
            //< setup >
            graphic_of_DrawArea.CompositingQuality = CompositingQuality.HighSpeed;
            graphic_of_DrawArea.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphic_of_DrawArea.CompositingMode = CompositingMode.SourceCopy;
            //</ setup >

            //< draw into placeholder >
            //*imports the image into the drawarea
            graphic_of_DrawArea.DrawImage(source_Bitmap, 0, 0, new_Width, new_Height);
            //</ draw into placeholder >

            //--< Output as .Jpg >--
            using (var output = System.IO.File.Open(output_Image_Path, FileMode.Create))
            {
                //< setup jpg >
                var qualityParamId = System.Drawing.Imaging.Encoder.Quality;
                var encoderParameters = new EncoderParameters(1);
                encoderParameters.Param[0] = new EncoderParameter(qualityParamId, quality);
                //</ setup jpg >

                //< save Bitmap as Jpg >
                var codec = ImageCodecInfo.GetImageDecoders().FirstOrDefault(c => c.FormatID == ImageFormat.Jpeg.Guid);
                new_DrawArea.Save(output, codec, encoderParameters);
                //resized_Bitmap.Dispose ();
                output.Close();
                //</ save Bitmap as Jpg >
            }
            //--</ Output as .Jpg >--
            graphic_of_DrawArea.Dispose();
        }
        source_Bitmap.Dispose();
        //---------------</ Image_resize() >---------------
    }
}

It's that I was using this method in other project before and it was working well, but I don't know why it doesn't work here at this project! Anyone can help?

0 Answers
Related