c# - Error on adjusting jpeg quality: Value cannot be null.Parameter name: structure -
i have method take image, make copy resizing, , return byte array. have attempted add ability adjust quality of image per doc:
http://msdn.microsoft.com/en-us/library/bb882583(v=vs.110).aspx
image image = image.fromfile(_filepath); image newimage = new bitmap(newwidth, newheight); using (graphics graphicshandle = graphics.fromimage(newimage)) { graphicshandle.interpolationmode = interpolationmode.highqualitybicubic; graphicshandle.drawimage(image, 0, 0, newwidth, newheight); } memorystream memstream = new memorystream(); encoderparameters myencoderparameters = new encoderparameters(1); imagecodecinfo encoder = imagecodecinfo.getimagedecoders().singleordefault(c => c.mimetype == contenttype); system.drawing.imaging.encoder myencoder = system.drawing.imaging.encoder.quality; encoderparameter myencoderparameter = new encoderparameter(myencoder, 50l); newimage.save(memstream, encoder, myencoderparameters); return memstream.toarray();
when call newimage.save()
, error:
an exception of type 'system.argumentnullexception' occurred in system.drawing.dll not handled in user code
message is:
value cannot null. parameter name: structure
msdn says have argumentnullexception when calling save() overload if stream null.
are sure no other (omitted?) code not nullifying stream? sure site of exception?
Comments
Post a Comment