c# - Convert bitmaps to one multipage TIFF image in .NET 2.0 -
how can convert array of bitmaps brand new image of tiff format, adding bitmaps frames in new tiff image?
using .net 2.0.
start first bitmap putting image object
bitmap bitmap = (bitmap)image.fromfile(file);
save bitmap memory tiff
memorystream bytestream = new memorystream(); bitmap.save(bytestream, imageformat.tiff);
put tiff image object
image tiff = image.fromstream(bytestream)
prepare encoders:
imagecodecinfo encoderinfo = getencoderinfo("image/tiff"); encoderparameters encoderparams = new encoderparameters(2); encoderparameter parameter = new encoderparameter( encoder.compression, (long)encodervalue.compressionccitt4); encoderparams.param[0] = parameter; parameter = new encoderparameter(encoder.saveflag, (long)encodervalue.multiframe); encoderparams.param[1] = parameter;
save file:
tiff.save(soutfilepath, encoderinfo, encoderparams);
for subsequent pages, prepare encoders:
encoderparameters encoderparams = new encoderparameters(2); encoderparameter saveencodeparam = new encoderparameter( encoder.saveflag, (long)encodervalue.framedimensionpage); encoderparameter compressionencodeparam = new encoderparameter( encoder.compression, (long)encodervalue.compressionccitt4); encoderparams.param[0] = compressionencodeparam; encoderparams.param[1] = saveencodeparam; tiff.saveadd(/* next image tiff - same above memory */, encoderparams);
finally flush file:
encoderparameter saveencodeparam = new encoderparameter( encoder.saveflag, (long)encodervalue.flush); encoderparams = new encoderparameters(1); encoderparams.param[0] = saveencodeparam; tiff.saveadd(encoderparams);
that should started.
Comments
Post a Comment