Return to FunctionReference page
Function
SWFBitmap newSWFBitmap_fromInput(SWFInput input);
Purpose
- Creates a SWFBitmap from a SWFInput.
Parameters
SWFInput input - The SWFInput object you want to read, holding the image data.
Returns
- A SWFBitmap on success, NULL on failure.
Language
- C
Ming version
- (unknown). At least 0.4.0 and onwards, possibly earlier versions as well.
Notes
- This function is able to understand PNG, JPEG, GIF, and DBL files for input.
Example
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <ming.h>
4
5 int main(void)
6 {
7 // Create local variables
8 SWFFillStyle bitmap_fill;
9 int bitmap_height;
10 int bitmap_width;
11 FILE *file_pointer;
12 int i;
13 SWFDisplayItem image_display_item;
14 SWFInput input_image;
15 SWFShape shape_object;
16 SWFBitmap test_image;
17 SWFMovie test_movie;
18
19
20 // Initialise the movie structure in memory
21 Ming_init();
22 test_movie = newSWFMovieWithVersion(7);
23
24 // Set the desired compression level for the output (9 = maximum compression)
25 Ming_setSWFCompression(9);
26
27 // Adjust the dimensions of the movie
28 SWFMovie_setDimension(test_movie, 800, 600);
29
30 // Set the frame rate for the movie to 24 frames per second
31 SWFMovie_setRate(test_movie, 24.0);
32
33 // Set up a file pointer, pointing to an image file we want to use
34 file_pointer = fopen("image.jpg", "rb");
35 if (file_pointer == NULL)
36 {
37 fprintf(stderr, "Image file could not be opened\n");
38 return EXIT_FAILURE;
39 }
40
41 // Create the SWFInput object from the file pointer
42 input_image = newSWFInput_file(file_pointer);
43 if (NULL == input_image)
44 {
45 // We couldn't open the file, so exit
46 return EXIT_FAILURE;
47 }
48
49 // Read from the input channel, turning it into a bitmap object we can use
50 test_image = newSWFBitmap_fromInput(input_image);
51 if (NULL == test_image)
52 {
53 // Something went wrong, so exit
54 return EXIT_FAILURE;
55 }
56
57 // Query the dimensions of the bitmap
58 bitmap_height = SWFBitmap_getHeight(test_image);
59 bitmap_width = SWFBitmap_getWidth(test_image);
60
61 // Turn the bitmap into a fill
62 bitmap_fill = newSWFBitmapFillStyle(test_image, SWFFILL_CLIPPED_BITMAP);
63
64 // Create the shape object we want
65 shape_object = newSWFShape();
66 SWFShape_setLine(shape_object, 1, 0x00, 0x00, 0x00, 0xff);
67 SWFShape_setRightFillStyle(shape_object, bitmap_fill);
68 SWFShape_drawLine(shape_object, bitmap_width, 0.0);
69 SWFShape_drawLine(shape_object, 0.0, bitmap_height);
70 SWFShape_drawLine(shape_object, -(bitmap_width), 0.0);
71 SWFShape_drawLine(shape_object, 0.0, -(bitmap_height));
72
73 // Add the shape object to the movie
74 image_display_item = SWFMovie_add(test_movie, (SWFBlock) shape_object);
75
76 // Move to 100, 100
77 SWFDisplayItem_moveTo(image_display_item, 100.00, 100.0);
78
79 // Progressively move the square down and to the right
80 for (i = 0; i <= 250; i++)
81 {
82 SWFMovie_nextFrame(test_movie);
83 SWFDisplayItem_move(image_display_item, 2, 2);
84 }
85
86 // Save the swf movie file to disk
87 SWFMovie_save(test_movie, "ming-test.swf");
88
89 // Free the swf movie in memory
90 destroySWFMovie(test_movie);
91
92 // Free the swf bitmap object
93 destroySWFBitmap((SWFBitmap) test_image);
94
95 // Free the swf input object
96 destroySWFInput(input_image);
97
98 return EXIT_SUCCESS;
99 }