c# - Detect a corrupt image file -
hi clever guys,
im faceing bit of challenge here. im supposed create several different pdf's containing multiple (not similar) images.
unfortunately of images corrupt/defect. causes creation of partikular pdf fail/dump.
is there way can test image prior creation of pdf?
please gentle me. im not expert.
i found out system.drawings.image can test formats. better nothing guess (it reduce subset significantly).
but when using itextsharp.text.image creation of pdf's. dont know how use the system.drawings.image
because when try image newimage = image.fromfile("sampimag.jpg");
(image) refers itextsharp.text.image
class.
system.drawings.image abstract, i've tried create subclass.
public class imagetest : system.drawing.image { }
now error message:"error 1 type 'system.drawing.image' has no constructors defined"
trying investigate constructors can use gives me attempt.
public class imagetest : system.drawing.image { imagetest(string filename); { } }
but doesn't work.
please inform me if there information need relevant investigating matter.
thanks in advance.
you should able use
public bool isvalidimagefile (string imagefile) { try { // using important avoid stressing garbage collector using (var test = system.drawing.image.fromfile(imagefile)) { // image has loaded , fine return true; } } catch { // technically exceptions may not indicate corrupt image, unlikely issue return false; } }
Comments
Post a Comment