7. Multi-Frame image
In order to catch the third season of the hero's schedule, I decided to set a one-week episode. In the seventh episode heroes, Peter's function was absorbed by his father. So my seventh episode of this series is about part of the functionality that GDI + does not fully implement.
Multi-frame image is defined as having multiple frames in one image, with few formats supporting multiple frames, only TIFF and GIF. None of the other formats can be stored as multiple-frame images. TIFF can support many pages, and GIF animations also support multiple frames. Using GDI + can generate multiple-frame TIFF, but there is no way to achieve the creation of GIF animation, may be due to the patent. First let's look at how to generate a multiple-frame TIFF image.
1 public void Createmultiframetiff (string resultimage, String image1, params string [] images)
2 {
3//read Multiple frames, the frames ' size can be different
4 Image frame1 = Image.FromFile (image1);
5 int length = images. Length;
6 image[] frames = new Image[length];
7 for (int i = 0; i < length; i++)
8 {
9 Frames [i] = Image.FromFile (Images[i]);
10}
11
The//set the "the" "the" base bitmap
Bitmap Bmpresult = (Bitmap) frame1;
14
//create encoder parameters with different values
encoderparameters parameters = new EncoderParameters (1);
parameters. Param[0] = new Encoderparameter (Encoder.saveflag, (long) encodervalue.multiframe);
18
//find Tiff codec
list<imagecodecinfo> supportedcodecs = new list<imagecodecinfo> ();
Supportedcodecs.addrange (Imagecodecinfo.getimageencoders ());
ImageCodecInfo tiffcodecinfo = Supportedcodecs.find (
delegate (imagecodecinfo info)
24 {
return info. Mimetype.equals (
System.Net.Mime.MediaTypeNames.Image.Tiff,
stringcomparison.ordinalignorecase);
28}
29);
30
//save the A stream.
Bmpresult.save (Resultimage, tiffcodecinfo, parameters);
33
//save the second frame into the TIFF
parameters. Param[0] = new Encoderparameter (Encoder.saveflag, (long) encodervalue.framedimensionpage);
foreach (Image frame in frames)
37 {
Bmpresult.saveadd (frame, parameters);
39}
40
//flush the Stream
Parameters. Param[0] = new Encoderparameter (Encoder.saveflag, (long) encodervalue.flush);
bmpresult.saveadd (parameters);
44
//dispose All
frame1. Dispose ();
foreach (Image frame in frames)
48 {
frame. Dispose ();
50}
Wuyi Bmpresult.dispose ();
52}
Here we use the encoderparameters to set the parameters of the image encoding, first set the multiple frame properties (16,17 line) when the first frame is saved, then get the TIFF encoder (20-29 lines). First frame is saved using encoderparamters and ImageCodecInfo, and new frames are added using the SaveAdd method. Finally flush the flow, is actually optional, because in bitmap dispose of the time will automatically flush.
Reading multiple-frame TIFF is simpler, call Getframecount and selectactiveframe directly, and we can get all the frames by line 1 below and select the current frame by line 2.
1 int count = bmp.GetFrameCount (FrameDimension.Page);
2 bmp.SelectActiveFrame (FrameDimension.Page, 1);
GDI + can read GIF animations, different from the above code 1, 2 lines, to use the Framedimension.time parameter to pass in. Although GDI + does not have out-of-the-box function implementations to generate GIF animations, there are other ways to do that. There is nothing that cannot be done this year, only unexpected. But that method is too complex and the bottom, and so when heroes inside Peter take back the ability, I tell you again.
It's the first day here.