C की graphics.h Library
In this page:
#include <graphics.h>
int gd = DETECT, gm;
initgraph(&gd, &gm, ""); // enter graphics mode
// ... drawing calls ...
getch();
closegraph(); // leave graphics mode
graphics.h Header
graphics.h header file 70 से ज़्यादा unique drawing और utility functions access करने के लिए एक gatekeeper की तरह काम करता है। यह आपके program coordinates को BGI drivers इस्तेमाल करके सीधे video controller memory में map करता है।
उदाहरण: The graphics.h Header
#include <graphics.h>
int main() {
initgraph(0, 0, "");
circle(100, 100, 50);
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
initgraph और closegraph
initgraph() function graphics driver load करता है और system को graphics mode में डालता है। closegraph() function graphics system shut down करता है, सारी allocated memory free करते हुए और text interface वापस load करते हुए।
उदाहरण: initgraph and closegraph
#include <graphics.h>
// Program execution starts in main()
int main() {
// Declare gd and set it to DETECT, gm
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
getch();
closegraph();
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
getmaxx और getmaxy
Screen sizes platforms के बीच अलग होते हैं। positions hardcode करने की बजाय, maximum resolution dynamically ढूंढने के लिए getmaxx() और getmaxy() इस्तेमाल करें। यह आपके designs को responsive रखता है।
उदाहरण: getmaxx and getmaxy
#include <graphics.h>
// Program execution starts in main()
int main() {
initgraph(0, 0, "");
// Declare centerX and set it to getmaxx() / 2
int centerX = getmaxx() / 2;
// Declare centerY and set it to getmaxy() / 2
int centerY = getmaxy() / 2;
putpixel(centerX, centerY, WHITE);
getch();
closegraph();
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
cleardevice और Background Options
cleardevice() function current graphics screen मिटाता है, इसे background color से भरते हुए। आप setbkcolor() function इस्तेमाल करके default background color set कर सकते हैं।
उदाहरण: cleardevice and Background Options
#include <graphics.h>
int main() {
initgraph(0, 0, "");
setbkcolor(BLUE);
cleardevice();
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Modern Compatibility Details
Standard C compiler packages (जैसे Windows या Linux पर GCC) out of the box graphics.h include नहीं करते। Modern setups custom BGI wrapper libraries इस्तेमाल करते हैं, जो same standard function signatures इस्तेमाल करती हैं।
उदाहरण: Modern Compatibility Details
#include <graphics.h>
int main() {
initgraph(0, 0, "");
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
initgraphcall करने से पहले draw करना, ताकि कुछ display न हो।initgraphको गलत BGI driver path pass करना, ताकि graphics mode initialize करने में यह fail हो जाए।closegraph()से पहलेgetch()भूल जाना, ताकि window तुरंत बंद हो जाए।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: