Skip to content

Navigation Menu

Sign in
Sign up

GDI+ error #19

jsb1992s started this conversation in General
May 4, 2023 · 1 comments · 6 replies
Discussion options

I find "A generic error occurred in GDI+" error when i call AddImageWatermark in async for several time
anyone can help me?

You must be logged in to vote

Replies: 1 comment 6 replies

Comment options

See #1

You must be logged in to vote
6 replies
Comment options

See #1

have you other suggest for windows

Comment options

You need to provide more details e.g.:

  • .net framework version
  • image type
  • your code sample
  • any other useful data...
Comment options

using (var img = Image.FromFile(srcImagePath))
 {
 FileInfo exportedFileInfo = new FileInfo(srcImagePath);
 tempoImagePath = Path.Combine(_hostingEnvironment.WebRootPath , cacheDirectory) + "//" + watermark.Id + StaticVariables.CharacterSeparator + "wm" + exportedExtension;
 if (watermark.WatermarkType.HasFlag(WatermarkType.Text))
 {
 img.AddTextWatermark(watermark.TextWaterMark);
 }
 if (watermark.WatermarkType.HasFlag(WatermarkType.Image))
 {
 var watermarkImage = Path.Combine(_hostingEnvironment.WebRootPath , originalDirectory , watermarkDirectory) + "//" + watermark.Id + exportedExtension;
 img.AddImageWatermark(watermarkImage);
 }
 img.SaveAs(temporaryImagePath);
 img.Dispose();
 }
Comment options

my .net version is 6
and image is png

Comment options

Are you sure that watermarkImage is referring to an image file correctly? I just tried with similar code and it worked fine.

btw, you may use the conditional extension methods to simplify the code as below:

using (var img = Image.FromFile("wwwroot/images/image.png"))
{
 // replace 'true' with the relevant condition check
 img.AddTextWatermarkIf(true, "TEXT WATERMARK") 
 .AddImageWatermarkIf(true, "wwwroot/images/logo.png", new ImageWatermarkOptions { Opacity = 30 }) 
 .SaveAs("wwwroot/images/new.png");
 img.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /