2015-09-17 86 views
-1

我正在寫一個C++代碼來創建一個多JPG圖片的動畫SWF文件。如何使用Visual C++中的swflib庫從多個.JPG圖像創建.swf文件?

現在,我有像「image_0」到「image_100」的圖片。我找到了一個庫。我認爲這會有所幫助。到目前爲止,我可以使用這個庫的方法來創建.SWF文件,而.SWF文件的大小是.JPG格式的圖片總和。

所以,我覺得我差不多完成了。但是,SWF不起作用。我瘋了。 下面這個是我修改了代碼:

`void CSWFLIBTestProjectDlg::CreateSWFMovie_Bitmap() 
{ 
    // Set movie params 
    SIZE_F movieSize = {100, 100}; 
    int frameRate = 14; 
    POINT_F pt; 

    // Create empty .SWF file 
    CSWFMovie swfMovie; 

    swfMovie.OpenSWFFile(_T("SWF Sample Movies/Sample2.swf"), movieSize, frameRate); 

    SWF_RGB bgColor = {255, 255, 255}; 
    swfMovie.SetBackgroundColor(bgColor); 

    // Define bitmap object 
    CSWFBitmap bitmap(2, (UCHAR*)"gif_0.jpg");//bm128 
    swfMovie.DefineObject(&bitmap, -1, true); 

    // Define custom shape 
    RECT_F shapeRect = {0, 0, 1000, 1000}; 
    CSWFShape shape(1, shapeRect, 1); 
    SWF_RGBA lineColor = {0, 0, 0, 255}; 
    shape.AddLineStyle(0, lineColor); 
    RECT_F bitmapRect = {0, 0, 1246, 622};        // size of the bitmap 
    RECT_F clipRect = {0, 0, 100, 100};         // where to fill 
    shape.AddBitmapFillStyle(bitmap.m_ID, SWF_FILLSTYLETYPE_BITMAP_0, bitmapRect, clipRect); 
    pt.x = 0; 
    pt.y = 0; 
    shape.ChangeStyle(1, 1, 0, &pt); 
    shape.AddLineSegment(100, 0); 
    shape.AddLineSegment(0, 100); 
    shape.AddLineSegment(-100, 0); 
    shape.AddLineSegment(0, -100); 


    swfMovie.DefineObject(&shape, shape.m_Depth, true); 

    swfMovie.ShowFrame(); 
    /**************************************** 
    * move 
    ****************************************/ 
    float i; 
    for (i=0; i<10; i++) 
    { 
     shape.Translate(i, 0); 
     swfMovie.UpdateObject(&shape, shape.m_Depth, NULL, -1); 
     swfMovie.ShowFrame(); 
     //if (i>200) 
     //{ 
     // swfMovie.RemoveObject(shape.m_Depth); 

     //} 

    } 


/**************************************** 
* add jpg 
****************************************/ 

    swfMovie.RemoveObject(shape.m_Depth); 

    for (int i=1;i<=100;i++) 
    { 
     char filename[100]; 
     sprintf(filename,"gif_%d%s",i,".jpg"); 

     CSWFBitmap bitmap2(3, (UCHAR*)filename);//gif_0 
     swfMovie.DefineObject(&bitmap2, -1, true);// 

     // Define custom shape 
     RECT_F shapeRect2 = {0, 0, 1000, 1000}; 
     CSWFShape shape2(1, shapeRect2, 1); 
     SWF_RGBA lineColor2 = {0, 0, 0, 255}; 
     shape2.AddLineStyle(0, lineColor2); 
     RECT_F bitmapRect2 = {0, 0, 1246, 622};        // size of the bitmap 
     RECT_F clipRect2 = {0, 0, 100, 100};         // where to fill 
     shape2.AddBitmapFillStyle(bitmap2.m_ID, SWF_FILLSTYLETYPE_BITMAP_0, bitmapRect2, clipRect2); 
     pt.x = 0; 
     pt.y = 0; 
     shape2.ChangeStyle(1, 1, 0, &pt); 
     shape2.AddLineSegment(100, 0); 
     shape2.AddLineSegment(0, 100); 
     shape2.AddLineSegment(-100, 0); 
     shape2.AddLineSegment(0, -100); 

     swfMovie.UpdateObject(&shape2, shape2.m_Depth, NULL, -1); 
     //swfMovie.DefineObject(&shape2, shape2.m_Depth, true); 

     swfMovie.ShowFrame(); 
     //swfMovie.RemoveObject(shape2.m_Depth); 


    } 








    // Close .SWF file 
    swfMovie.CloseSWFFile(); 
}` 

你能告訴我什麼是錯我的代碼?提前致謝。

回答

0

我已經找到一種方法來創建使用C++一組圖像的.SWF文件和swflib library.you可以從the lib file website下載它。在其中有一個名爲方法:CreateSWFMovie_Bitmap()這裏爲i改性

空隙CSWFLIBTestProjectDlg :: CreateSWFMovie_Bitmap() {

SIZE_F movieSize = {4000, 4000}; 
int frameRate = 40; 
POINT_F pt; 


CSWFMovie swfMovie; 
swfMovie.OpenSWFFile(_T("SWF Sample Movies/Sample2.swf"), movieSize, frameRate); 
SWF_RGB bgColor = {255, 255, 255}; 
swfMovie.SetBackgroundColor(bgColor); 


CSWFBitmap bitmap(2, (UCHAR*)"bm128.jpg"); 
swfMovie.DefineObject(&bitmap, -1, false); 


RECT_F shapeRect = {0, 0, 1000, 1000};//shape大小 
CSWFShape shape(1, shapeRect, 1); 
SWF_RGBA lineColor = {0, 0, 0, 255}; 
shape.AddLineStyle(3, lineColor); 
RECT_F bitmapRect = {0, 0, 128, 128};        // size of the bitmap 
RECT_F clipRect = {0, 0, 100, 100};         // where to fill 
shape.AddBitmapFillStyle(bitmap.m_ID, SWF_FILLSTYLETYPE_BITMAP_0, bitmapRect, clipRect); 
pt.x = 0; 
pt.y = 0; 
shape.ChangeStyle(1, 1, 0, &pt); 
shape.AddLineSegment(100, 0); 
shape.AddLineSegment(0, 100); 
shape.AddLineSegment(-100, 0); 
shape.AddLineSegment(0, -100); 
swfMovie.DefineObject(&shape, shape.m_Depth, true); 
swfMovie.ShowFrame(); 



for (int i=0; i<100; i++) 
{ 
    char filename[50]=""; 
    sprintf(filename,"gif_%d%s",i,".jpg"); 
    CSWFBitmap bitmap2(300+i, (UCHAR*)filename); 
    swfMovie.DefineObject(&bitmap2, -1, false);//false 
    CSWFShape shape2(7+i,shapeRect,2+i);//depth值也不能一樣 id不能重複 
    shape2.AddLineStyle(3, lineColor); 
    RECT_F bitmapRect2 = {0, 0, 128, 128};        
    RECT_F clipRect2 = {0, 0, 100, 100};          
    shape2.AddBitmapFillStyle(bitmap2.m_ID, SWF_FILLSTYLETYPE_BITMAP_0, bitmapRect2, clipRect2); 

    pt.x = 0; 
    pt.y = 0; 
    shape2.ChangeStyle(1, 1, 0, &pt); 
    shape2.AddLineSegment(1000, 0); 
    shape2.AddLineSegment(0, 1000); 
    shape2.AddLineSegment(-1000, 0); 
    shape2.AddLineSegment(0, -1000); 
    shape2.Translate(80, 0); 
    swfMovie.DefineObject(&shape2, shape2.m_Depth, true);//必須define才能動 可以不update 

    swfMovie.ShowFrame(); 


} 

}

代碼
相關問題