-
-
Notifications
You must be signed in to change notification settings - Fork 16
GDI+ error
#19
I find "A generic error occurred in GDI+" error when i call AddImageWatermark in async for several time
anyone can help me?
All reactions
Replies: 1 comment 6 replies
See #1
All reactions
6 replies
See #1
have you other suggest for windows
All reactions
You need to provide more details e.g.:
- .net framework version
- image type
- your code sample
- any other useful data...
All reactions
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(); }
All reactions
my .net version is 6
and image is png
All reactions
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(); }
All reactions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment