Animate GIF in C
-
Hello, I dont find any way to play the animation of a loaded GIF file in C, not C++. Is it possible ?? I tried using GDI+ with the gdiplusflat.h and i aborded with the error "unknown type: Graphics, Image, or Pen" when compiling. Tried too with the types GpGraphics, GpImage, or GpPen and then i get an error on Color() and dont find what was the problem... Yes, maybe i dont need Color() or Pen, but it was for testing if GDI+ was really there. GdiplusStartupInput and GdiplusStartup() seem working. Next, after many test/search, i found this, a C code for displaying GIF image : https://www.codeproject.com/Articles/3283/Library-to-display-an-image-JPG-GIF-BMP-in-lin JPG and BMP are ok, but GIF dont play the frames and looks to have no alpha. So, is there a way to do this with the OLE !? Or any other way that dont need switching to C++ I'm with CodeBlock IDE (MinGW and GCC) using the Win32 GUI. Please help me! im a good rookie who begin in C :) Retry edit: ----------- So i retry GDI+ and "pass" the error Color() with Color(Blue) and now it's DrawLine() error: undefined reference to pen... C++ good code:
Graphics graphics(HDC hdc);
Pen pen(Color(255, 0, 0, 255));
graphics.DrawLine(&pen, 0, 0, 200, 100);C bad code:
GpGraphics graphics(HDC hdc);
GpPen pen(Color(Blue));
GdipDrawLine(&graphics, &pen, 0, 0, 200, 100);Have tried without success some: GpPen myPen = pen(Color(Blue)); Ok i resign C/GDI+ without help, and i dont know if GpX/GdipX is the right way.. The msdn docs say "Windows GDI+ is a class-based API for C/C++ programmers" but i dont find anybody that have implemented it in C. Tried GDI+ with C++ project and get it working directly.. damn... I hope there is something for C Please HELP !
-
Hello, I dont find any way to play the animation of a loaded GIF file in C, not C++. Is it possible ?? I tried using GDI+ with the gdiplusflat.h and i aborded with the error "unknown type: Graphics, Image, or Pen" when compiling. Tried too with the types GpGraphics, GpImage, or GpPen and then i get an error on Color() and dont find what was the problem... Yes, maybe i dont need Color() or Pen, but it was for testing if GDI+ was really there. GdiplusStartupInput and GdiplusStartup() seem working. Next, after many test/search, i found this, a C code for displaying GIF image : https://www.codeproject.com/Articles/3283/Library-to-display-an-image-JPG-GIF-BMP-in-lin JPG and BMP are ok, but GIF dont play the frames and looks to have no alpha. So, is there a way to do this with the OLE !? Or any other way that dont need switching to C++ I'm with CodeBlock IDE (MinGW and GCC) using the Win32 GUI. Please help me! im a good rookie who begin in C :) Retry edit: ----------- So i retry GDI+ and "pass" the error Color() with Color(Blue) and now it's DrawLine() error: undefined reference to pen... C++ good code:
Graphics graphics(HDC hdc);
Pen pen(Color(255, 0, 0, 255));
graphics.DrawLine(&pen, 0, 0, 200, 100);C bad code:
GpGraphics graphics(HDC hdc);
GpPen pen(Color(Blue));
GdipDrawLine(&graphics, &pen, 0, 0, 200, 100);Have tried without success some: GpPen myPen = pen(Color(Blue)); Ok i resign C/GDI+ without help, and i dont know if GpX/GdipX is the right way.. The msdn docs say "Windows GDI+ is a class-based API for C/C++ programmers" but i dont find anybody that have implemented it in C. Tried GDI+ with C++ project and get it working directly.. damn... I hope there is something for C Please HELP !
There is no simple solution to show an animated GIF. You have to write code that acts as a player (or look for existing code). All Windows drawing functions are bitmap based. When loading images of other types like JPEG and GIF, they are converted to BMP bitmaps. You might have a look at the article Adding GIF-animation using GDI+[^]. For a MFC implementation see GIF Animation Control[^]. There is also a Microsoft example using Direct2D: Windows Imaging Component Animated GIF Win32 Sample[^].
-
There is no simple solution to show an animated GIF. You have to write code that acts as a player (or look for existing code). All Windows drawing functions are bitmap based. When loading images of other types like JPEG and GIF, they are converted to BMP bitmaps. You might have a look at the article Adding GIF-animation using GDI+[^]. For a MFC implementation see GIF Animation Control[^]. There is also a Microsoft example using Direct2D: Windows Imaging Component Animated GIF Win32 Sample[^].
Thanks you for your quick answer! im overcoded :D So there is no way to play GIF without C++ I'm looking at the gdiplusflat because of this topic https://stackoverflow.com/questions/5114591/how-to-use-gdi-in-c I use the gdiplus*.h from https://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-16.01mingw-nosetup.zip/download And dont get same errors as in the stackoverflow topic. And dont understand exactly what we have to change to make GDI+ working with C. So im interested if anybody know... Finally i think i will switch to C++ to avoid future problems like this...
-
Thanks you for your quick answer! im overcoded :D So there is no way to play GIF without C++ I'm looking at the gdiplusflat because of this topic https://stackoverflow.com/questions/5114591/how-to-use-gdi-in-c I use the gdiplus*.h from https://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-16.01mingw-nosetup.zip/download And dont get same errors as in the stackoverflow topic. And dont understand exactly what we have to change to make GDI+ working with C. So im interested if anybody know... Finally i think i will switch to C++ to avoid future problems like this...
If switching to C++ is possible, do it. You can still write C and let it just compile by a C++ compiler. It should be possible to use the Gdi+ Flat API with plain C. But then you are resticted to those API calls and will probably find only a few or even no examples. See also Graphics Functions (Windows)[^] and GDI+ Flat API (Windows)[^] :
Quote:
It is recommended that you do not directly call the functions in the flat API. Whenever you make calls to GDI+, you should do so by calling the methods and functions provided by the C++ wrappers. Microsoft Product Support Services will not provide support for code that calls the flat API directly.
-
If switching to C++ is possible, do it. You can still write C and let it just compile by a C++ compiler. It should be possible to use the Gdi+ Flat API with plain C. But then you are resticted to those API calls and will probably find only a few or even no examples. See also Graphics Functions (Windows)[^] and GDI+ Flat API (Windows)[^] :
Quote:
It is recommended that you do not directly call the functions in the flat API. Whenever you make calls to GDI+, you should do so by calling the methods and functions provided by the C++ wrappers. Microsoft Product Support Services will not provide support for code that calls the flat API directly.
So im always in C, yes im not so a resigner... and rereading the msdn docs made me think another "more right manner" to speak to GDI+ This time i get compiling without error! but nothing is draw and the app crash on files functions... It look like GDI+ is here but not there... Maybe a problem with the header in C for GDI+, or maybe a problem with the compiler command line, linker, i dont know... I get GDI+ working in C++ just with uncommenting //using namespace Gdiplus; And with the same build options lib linker/search/include Maybe a problem with the "*var" "&var" or just "var", yes i dont well know exactly when i have to write the & or the * or just simple var. I just know &var is the reference address of the pointer, and *var is the value or create pointer on var, so if you have good explicit explanation/link about how to correctly speak to these func(var, *var, type*, type**) Some guys speak about the StdAfx.h but i dont have these afx*.h files. I read two samples, and it can contain include to other afx + the same declaration as my header for GDI+. But it seem useless because i can get GDI+ working compiling in C++ without these afx files. I have put the gdiplus.dll everywhere... Please really help me just getting GDI+ running with C, try made working it on your side. Please :) And it is not for doing my exercise or selling my GDI+ initialization program, it's just for learning how windows app can be done (and codded in the best possible way for the end user) If you know it is possible, please do it! i dont have your experience to resolve the problem, and my imagination have some limit without explicit docs, so please show me howtodo! and i think it will take you about 5-30min to just made GDI+ running in a C winapi program (i hope..) And its not just for me, but all other interested too, and maybe you if you dont alway know, and it look its not a common skill having GDI+ working in C... so it's maybe not "loosing" your time. Promise, i will done an howto if we success, or letting you do this if you want... and i will be happy helping you and other about web development. For finish, the goal seem just there! but i dont know enough at all to say that... but i see that it compile "fine" but crash in the app. Im a C/WinAPI rookie that want to learn, and i learn good when i meet a real problem for what i have to do. So please help me understanding my errors. Me, i see that if i get GDI+ functional in C, i maybe not need C++ for other things, because GDI+ give me all the rest i nee
-
So im always in C, yes im not so a resigner... and rereading the msdn docs made me think another "more right manner" to speak to GDI+ This time i get compiling without error! but nothing is draw and the app crash on files functions... It look like GDI+ is here but not there... Maybe a problem with the header in C for GDI+, or maybe a problem with the compiler command line, linker, i dont know... I get GDI+ working in C++ just with uncommenting //using namespace Gdiplus; And with the same build options lib linker/search/include Maybe a problem with the "*var" "&var" or just "var", yes i dont well know exactly when i have to write the & or the * or just simple var. I just know &var is the reference address of the pointer, and *var is the value or create pointer on var, so if you have good explicit explanation/link about how to correctly speak to these func(var, *var, type*, type**) Some guys speak about the StdAfx.h but i dont have these afx*.h files. I read two samples, and it can contain include to other afx + the same declaration as my header for GDI+. But it seem useless because i can get GDI+ working compiling in C++ without these afx files. I have put the gdiplus.dll everywhere... Please really help me just getting GDI+ running with C, try made working it on your side. Please :) And it is not for doing my exercise or selling my GDI+ initialization program, it's just for learning how windows app can be done (and codded in the best possible way for the end user) If you know it is possible, please do it! i dont have your experience to resolve the problem, and my imagination have some limit without explicit docs, so please show me howtodo! and i think it will take you about 5-30min to just made GDI+ running in a C winapi program (i hope..) And its not just for me, but all other interested too, and maybe you if you dont alway know, and it look its not a common skill having GDI+ working in C... so it's maybe not "loosing" your time. Promise, i will done an howto if we success, or letting you do this if you want... and i will be happy helping you and other about web development. For finish, the goal seem just there! but i dont know enough at all to say that... but i see that it compile "fine" but crash in the app. Im a C/WinAPI rookie that want to learn, and i learn good when i meet a real problem for what i have to do. So please help me understanding my errors. Me, i see that if i get GDI+ functional in C, i maybe not need C++ for other things, because GDI+ give me all the rest i nee
One problem is that you are using CodeBlocks with MinGW and GCC. That is rather uncommon for Windows applications and requires additional work and knowledge. I know GCC/G++ from Linux but have it never used for Windows and have not used CodeBlocks. I suggest to use Visual Studio instead if possible. It is free for personal use and even for commercial use by small companies. Arguments are passed in C++ like in C: By value or by pointer. But C++ supports also pass by reference (when the
&
operator is used in the function declaration). It is effectively (generated assembly) the same as pass by pointer but safer (an existing instance must be passed so that passing invalid pointers likeNULL
are avoided). That is basic C and C++ stuff. StdAfx.h is a special header file used by VisualStudio that has to be included on top of each source file when used. It is used with pre-compiled headers (reducing build time) and for global project wide definitions like minimum supported Windows version. Other Afx* files are again VS specific. The are the header files for the C++ MFC libary (Microsoft Foundation Class Library - Wikipedia[^]).#include //#include //at start i was writing this, but its include in gdiplus.h
gdiplus.h is C++. If you want to do plain C, you have to use gdiplusflat.h.
#pragma comment(lib, "gdiplus.lib")//i get warning ignoring, and i include it with the linker setting : libgdiplus.a (as i understand...)
That is again a VS specific statement that is not supported by GCC. My conclusion:
- Use the common tools (VS) for Windows application. That applies especially to beginners.
- Don't use source code supplied for different tools when not knowing what it is doing and how to convert it for your tools.
- Go for C++ as also mentioned in the SO thread from your initial post because using the unsupported flat API might require a lot of additional work (and knowledge) to get it compiled and running.
- This is a very specific request (GDI+ with plain C using GCC) which is from my point of view only of interest for very few people
-
So im always in C, yes im not so a resigner... and rereading the msdn docs made me think another "more right manner" to speak to GDI+ This time i get compiling without error! but nothing is draw and the app crash on files functions... It look like GDI+ is here but not there... Maybe a problem with the header in C for GDI+, or maybe a problem with the compiler command line, linker, i dont know... I get GDI+ working in C++ just with uncommenting //using namespace Gdiplus; And with the same build options lib linker/search/include Maybe a problem with the "*var" "&var" or just "var", yes i dont well know exactly when i have to write the & or the * or just simple var. I just know &var is the reference address of the pointer, and *var is the value or create pointer on var, so if you have good explicit explanation/link about how to correctly speak to these func(var, *var, type*, type**) Some guys speak about the StdAfx.h but i dont have these afx*.h files. I read two samples, and it can contain include to other afx + the same declaration as my header for GDI+. But it seem useless because i can get GDI+ working compiling in C++ without these afx files. I have put the gdiplus.dll everywhere... Please really help me just getting GDI+ running with C, try made working it on your side. Please :) And it is not for doing my exercise or selling my GDI+ initialization program, it's just for learning how windows app can be done (and codded in the best possible way for the end user) If you know it is possible, please do it! i dont have your experience to resolve the problem, and my imagination have some limit without explicit docs, so please show me howtodo! and i think it will take you about 5-30min to just made GDI+ running in a C winapi program (i hope..) And its not just for me, but all other interested too, and maybe you if you dont alway know, and it look its not a common skill having GDI+ working in C... so it's maybe not "loosing" your time. Promise, i will done an howto if we success, or letting you do this if you want... and i will be happy helping you and other about web development. For finish, the goal seem just there! but i dont know enough at all to say that... but i see that it compile "fine" but crash in the app. Im a C/WinAPI rookie that want to learn, and i learn good when i meet a real problem for what i have to do. So please help me understanding my errors. Me, i see that if i get GDI+ functional in C, i maybe not need C++ for other things, because GDI+ give me all the rest i nee
-
One problem is that you are using CodeBlocks with MinGW and GCC. That is rather uncommon for Windows applications and requires additional work and knowledge. I know GCC/G++ from Linux but have it never used for Windows and have not used CodeBlocks. I suggest to use Visual Studio instead if possible. It is free for personal use and even for commercial use by small companies. Arguments are passed in C++ like in C: By value or by pointer. But C++ supports also pass by reference (when the
&
operator is used in the function declaration). It is effectively (generated assembly) the same as pass by pointer but safer (an existing instance must be passed so that passing invalid pointers likeNULL
are avoided). That is basic C and C++ stuff. StdAfx.h is a special header file used by VisualStudio that has to be included on top of each source file when used. It is used with pre-compiled headers (reducing build time) and for global project wide definitions like minimum supported Windows version. Other Afx* files are again VS specific. The are the header files for the C++ MFC libary (Microsoft Foundation Class Library - Wikipedia[^]).#include //#include //at start i was writing this, but its include in gdiplus.h
gdiplus.h is C++. If you want to do plain C, you have to use gdiplusflat.h.
#pragma comment(lib, "gdiplus.lib")//i get warning ignoring, and i include it with the linker setting : libgdiplus.a (as i understand...)
That is again a VS specific statement that is not supported by GCC. My conclusion:
- Use the common tools (VS) for Windows application. That applies especially to beginners.
- Don't use source code supplied for different tools when not knowing what it is doing and how to convert it for your tools.
- Go for C++ as also mentioned in the SO thread from your initial post because using the unsupported flat API might require a lot of additional work (and knowledge) to get it compiled and running.
- This is a very specific request (GDI+ with plain C using GCC) which is from my point of view only of interest for very few people
Wow! i get it working!! Just removing the & from GdipDrawLineI(&graphics, &pen, x1, y1, x2, y2); I found this in C++ by resolving the pointer error i ended up when combining with the Gdiplus::Func and helped by the PureBasic docs... And this occur just during the long VS2012 install :D it is sign that i have to stay with codeblock... Sorry but i have to say that your help was not terrible, and it seem you are often unclear, not precisely. I said rookie with possible bad pointer, but you dont even verify my only two main pointer, graphics and pen, while the GDI+ real func (from gdiplusflat) is just a line before. Jochen, dont take it bad ;) it is to improve your help! and i know there are lot of guys for their exercise :D but me i was the right man to really help... I very thank you anyway to have just trying helping me, bad or good answer, i finish to success with this topic, and "alone" like in my habit, so now i have well understand how to speak GDI+ with C. Thanks you for #pragma comment specific VS, and especially the MinGW GCC observation that made me do some search and discover some good things that i have to explore... So it was not for nothing, i have learn other things because of you! so more than just GDI+, and i really thank you for your time! And i admit i have little abuse with the * & because i always have not well tested these whereas i can do it alone, to see what is really going on on the var. It is because i was believe get it enough, based on my well know php and his var passed by reference, but i will really test these pointer soon. My english is maybe not so good too, and not pleasant to read, i'm sorry for that... And im new here.. know for my future ask, i try never ask, and if i finish to do it, this is that i really need value help. And i havent register to post this question, but to download sample source code, excellent theses articles to learn!! For finish, my first impressions about C/WinAPI after two weeks 18/24h, from a web dev man, is that it seem very very hard compared to php/javascript. A total chinese at start! A thing that will miss me a lot is multi dimensional array with string index, and the html/css for build the design too... So im for the moment trying preparing my primary framework... Bye and good code ;) PS: i think i will valid your 2nd or 1st answer ;P
-
If you must use C rather than C++, then you should also use Windows GDI (Windows)[^] not GDI+.
-
Do you know if it is possible to play the animation of the GIF with GDI ? I am looking for something that can load and draw BMP, JPG, PNG, GIF (+ animation)
The image handling in GDI is somewhat basic and generally only able to handle Bitmaps, so you would most likely need to add a lot of extra code yourself to do the work. Your only real option is to move forward into C++, which is not as painful as it may seem.
-
Wow! i get it working!! Just removing the & from GdipDrawLineI(&graphics, &pen, x1, y1, x2, y2); I found this in C++ by resolving the pointer error i ended up when combining with the Gdiplus::Func and helped by the PureBasic docs... And this occur just during the long VS2012 install :D it is sign that i have to stay with codeblock... Sorry but i have to say that your help was not terrible, and it seem you are often unclear, not precisely. I said rookie with possible bad pointer, but you dont even verify my only two main pointer, graphics and pen, while the GDI+ real func (from gdiplusflat) is just a line before. Jochen, dont take it bad ;) it is to improve your help! and i know there are lot of guys for their exercise :D but me i was the right man to really help... I very thank you anyway to have just trying helping me, bad or good answer, i finish to success with this topic, and "alone" like in my habit, so now i have well understand how to speak GDI+ with C. Thanks you for #pragma comment specific VS, and especially the MinGW GCC observation that made me do some search and discover some good things that i have to explore... So it was not for nothing, i have learn other things because of you! so more than just GDI+, and i really thank you for your time! And i admit i have little abuse with the * & because i always have not well tested these whereas i can do it alone, to see what is really going on on the var. It is because i was believe get it enough, based on my well know php and his var passed by reference, but i will really test these pointer soon. My english is maybe not so good too, and not pleasant to read, i'm sorry for that... And im new here.. know for my future ask, i try never ask, and if i finish to do it, this is that i really need value help. And i havent register to post this question, but to download sample source code, excellent theses articles to learn!! For finish, my first impressions about C/WinAPI after two weeks 18/24h, from a web dev man, is that it seem very very hard compared to php/javascript. A total chinese at start! A thing that will miss me a lot is multi dimensional array with string index, and the html/css for build the design too... So im for the moment trying preparing my primary framework... Bye and good code ;) PS: i think i will valid your 2nd or 1st answer ;P
Fine to hear that you got it working. But I never said that I know GDI for 20 years. I even have not used the plain Win32 API much because - as already mentioned - Windows applications are usually written in C++ (and other languages) rather than plain C and using the provided C++ libraries including MFC makes writing applications juch simpler. C++ is also strongly typed which means that passing arguments with wrong indirections result in a compiler error (if not casting them away). To notice that error in your code I would had to read the reference of the GDI function and compare with the passed arguments. Please understand that I (and others here) generally do not such because it would require to do it for the complete code.
Quote:
For finish, my first impressions about C/WinAPI after two weeks 18/24h, from a web dev man, is that it seem very very hard compared to php/javascript.
For that reason almost nobody uses the plain Win32 API anymore for GUI related tasks.
-
Fine to hear that you got it working. But I never said that I know GDI for 20 years. I even have not used the plain Win32 API much because - as already mentioned - Windows applications are usually written in C++ (and other languages) rather than plain C and using the provided C++ libraries including MFC makes writing applications juch simpler. C++ is also strongly typed which means that passing arguments with wrong indirections result in a compiler error (if not casting them away). To notice that error in your code I would had to read the reference of the GDI function and compare with the passed arguments. Please understand that I (and others here) generally do not such because it would require to do it for the complete code.
Quote:
For finish, my first impressions about C/WinAPI after two weeks 18/24h, from a web dev man, is that it seem very very hard compared to php/javascript.
For that reason almost nobody uses the plain Win32 API anymore for GUI related tasks.
Ok, i updated the little excess.. i concluded that because of your profile page. Sorry :) But i have prepare the code to be ready, to copy/paste it on a simple window program + one eventual past from msdn for testing imgFiles func + a FillRect winapi to uncomment for control it paint the right window. Hey no prob ;) and re thanks for this last things, yes this is the C++ compiler that found there is something bad on Gdiplus::GpPen *pen and Gdiplus::GpGraphics *graphics, the C him say no error. So finally i was getting GDI+ Flat in C++. For the Gui i cannot already really say... but i think i will maybe love, yes i'm "strange" guy :D I have done some many test and i get understand the window system (class + winproc) And now i really know from where come the Windows name :laugh: 2 months ago was trying making windows app in ASM, so i'm not so bad with C... :D And only now, i remember some keyword i was viewing in ASM too, and only now in C, i begin to little understand... So so so long time i would do what im going to do. All your tips are welcome...
-
Fine to hear that you got it working. But I never said that I know GDI for 20 years. I even have not used the plain Win32 API much because - as already mentioned - Windows applications are usually written in C++ (and other languages) rather than plain C and using the provided C++ libraries including MFC makes writing applications juch simpler. C++ is also strongly typed which means that passing arguments with wrong indirections result in a compiler error (if not casting them away). To notice that error in your code I would had to read the reference of the GDI function and compare with the passed arguments. Please understand that I (and others here) generally do not such because it would require to do it for the complete code.
Quote:
For finish, my first impressions about C/WinAPI after two weeks 18/24h, from a web dev man, is that it seem very very hard compared to php/javascript.
For that reason almost nobody uses the plain Win32 API anymore for GUI related tasks.
-
Jochen Arndt wrote:
almost nobody uses the plain Win32 API anymore for GUI related tasks.
But it is still quite easy to use, and so much simpler than MFC.
You hopefully mean by "simpler" that you can see in the source code what is happening. Each window must have for example it's own message loop while you just have a message map and handlers for non-default messages with MFC. However, the plain API is still useful for low level and non GUI tasks.
-
You hopefully mean by "simpler" that you can see in the source code what is happening. Each window must have for example it's own message loop while you just have a message map and handlers for non-default messages with MFC. However, the plain API is still useful for low level and non GUI tasks.
Jochen Arndt wrote:
Each window must have for example it's own message loop
Not in cases where there are client Windows inside a main, and I am not talking about MDI. But in MFC each Window needs a message map. I used Win32 and MFC when I was developing for a living, and never found that MFC made things significantly easier. However, as with all such questions, it's largely a matter of personal choice. I am sure there are plenty of MFC developers who hate Win32.