为什么我收到异常:运行应用程序时"System.Drawing.SafeNativeMethods+Gdip.CheckStatus(int status)"?



我使用一个名为:Image_resize的方法来调整图像的大小,但当我调用这个方法时,我得到:

ArgumentException:参数无效。系统绘画SafeNativeMethods+Gdip。CheckStatus(int status(

堆栈查询Cookie标头路由参数异常:参数为无效。系统绘画SafeNativeMethods+Gdip。CheckStatus(intstatus(系统。绘画位图。。ctor(字符串文件名,bool-useIcm(系统绘画位图。。ctor(字符串文件名(Keyhanatr。果心ImageMethods。图像转换器。Image_resize(字符串input_Image_Path,字符串output_Image_Pth,int new_Width(ImgMehods.cs+位图source_Bitmap=新位图(input_Image_Path(;Keyhanatr。果心ImageMethods。ImgMehods。CreateProductImg(IFormFileimgUp(+图像转换器。Image_resize(imgPath,thumbPath,150(;Keyhanatr。果心服务。产品。产品服务。AddProduct(产品product,IFormFile imgUp(+产品ImageName=ImgMehods。CreateProductImg(imgUp(;Keyhanatr。区域。管理控制器。产品控制器。创建(产品product,IFormFile imgUp(+_productServices。AddProduct(product,imgUp(;

还在某些行下获得绿色波浪形。使用的方法如下:

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() >---------------
}
}

我以前在其他项目中使用过这种方法,效果很好,但我不知道为什么它在这个项目中不起作用!有人能帮忙吗?

我遇到了同样的问题,发现应该先检查宽度和高度not zero

var new_DrawArea = new Bitmap(new_Width, new_Height)

相关内容

  • 没有找到相关文章

最新更新