Return to FunctionReference page
Function
SWFInput newSWFInput_file(FILE *f);
Purpose
- Creates a SWFInput object from a file pointer.
Parameters
FILE *f - A file pointer (i.e. created using fopen()) to the file to use.
Returns
- A SWFInput object on success, NULL if an error occurred.
Language
- C
Ming version
- (unknown). At least 0.4.0 and onwards, possibly earlier versions as well.
Notes
None as yet
Example
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <ming.h>
4
5 int main(void)
6 {
7 // Create local variables
8 FILE *file_pointer = NULL;
9 int i;
10 SWFDisplayItem image_display_item;
11 SWFInput input_image;
12 SWFJpegBitmap test_image;
13 SWFMovie test_movie;
14
15
16 // Initialise the movie structure in memory
17 Ming_init();
18 test_movie = newSWFMovieWithVersion(7);
19
20 // Set the desired compression level for the output (9 = maximum compression)
21 Ming_setSWFCompression(9);
22
23 // Set the background color for the movie
24 SWFMovie_setBackground(test_movie, 0x00, 0x00, 0x00);
25
26 // Adjust the dimensions of the movie
27 SWFMovie_setDimension(test_movie, 800, 600);
28
29 // Set the frame rate for the movie to 24 frames per second
30 SWFMovie_setRate(test_movie, 24.0);
31
32 // Set up a file pointer, pointing to an image file we want to use
33 file_pointer = fopen("image.jpg", "rb");
34 if (file_pointer == NULL)
35 {
36 fprintf(stderr, "Image file could not be opened\n");
37 return EXIT_FAILURE;
38 }
39
40 // Create the SWFInput object from the file pointer
41 input_image = newSWFInput_file(file_pointer);
42 if (NULL == input_image)
43 {
44 // We couldn't open the file, so exit
45 return EXIT_FAILURE;
46 }
47
48 // Read from the input channel, turning it into a bitmap object we can use
49 test_image = newSWFJpegBitmap_fromInput(input_image);
50 if (NULL == test_image)
51 {
52 // Something went wrong, so exit
53 return EXIT_FAILURE;
54 }
55
56 // Add the bitmap object to the movie (at 0,0)
57 image_display_item = SWFMovie_add(test_movie, (SWFBlock) test_image);
58
59 // Move to 100, 100
60 SWFDisplayItem_moveTo(image_display_item, 100.00, 100.0);
61
62 // Progressively move the square down and to the right
63 for (i = 0; i <= 250; i++)
64 {
65 SWFMovie_nextFrame(test_movie);
66 SWFDisplayItem_move(image_display_item, 2, 2);
67 }
68
69 // Save the swf movie file to disk
70 SWFMovie_save(test_movie, "ming-test.swf");
71
72 // Free the swf movie in memory
73 destroySWFMovie(test_movie);
74
75 // Free the swf JPEG bitmap object
76 destroySWFBitmap((SWFBitmap) test_image);
77
78 // Free the swf input object
79 destroySWFInput(input_image);
80
81 return EXIT_SUCCESS;
82 }