13 Lecture

CS410

Midterm & Final Term Short Notes

Graphics Device Interface

Graphics Device Interface (GDI) is a Windows API that facilitates drawing graphics and text on the screen and printers. It provides functions for 2D drawing, font rendering, and image manipulation, enabling developers to create graphical user in


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF

1. What does GDI stand for in computer graphics?

   a) Graphics Design Interface

   b) Graphics Display Interface

   c) Graphical Device Interface

   d) Graphical Display Interface


   Solution: c) Graphical Device Interface


2. Which Windows API provides functions for 2D drawing and font rendering?

   a) GDI

   b) GUI

   c) API

   d) DirectX


   Solution: a) GDI


3. Which GDI function is used to draw lines on the screen?

   a) DrawLine()

   b) LineTo()

   c) DrawPath()

   d) DrawSegment()


   Solution: b) LineTo()


4. What is the purpose of the SelectObject function in GDI?

   a) To select a font for drawing text.

   b) To select a color for filling shapes.

   c) To select a pen or brush for drawing operations.

   d) To select a file for image loading.


   Solution: c) To select a pen or brush for drawing operations.


5. Which GDI function is used to draw text on the screen?

   a) DrawText()

   b) TextOut()

   c) WriteText()

   d) PrintText()


   Solution: b) TextOut()


6. Which GDI object is used to store graphical images?

   a) Pen

   b) Brush

   c) Bitmap

   d) Font


   Solution: c) Bitmap


7. What is the purpose of the StretchBlt function in GDI?

   a) To draw a filled rectangle.

   b) To resize an image.

   c) To draw an elliptical shape.

   d) To draw text in bold format.


   Solution: b) To resize an image.


8. Which GDI function is used to create a custom color brush?

   a) CreateSolidBrush()

   b) CreatePatternBrush()

   c) CreateColorBrush()

   d) CreateCustomBrush()


   Solution: a) CreateSolidBrush()


9. How is transparency achieved in GDI?

   a) By using the SetTransparent function.

   b) By selecting a transparent color.

   c) GDI does not support transparency.

   d) By using the SetLayeredWindowAttributes function.


   Solution: d) By using the SetLayeredWindowAttributes function.


10. Which GDI function is used to draw an arc?

    a) DrawArc()

    b) ArcTo()

    c) Arc()

    d) ArcSegment()


    Solution: c) Arc()



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF

1. What is Graphics Device Interface (GDI) in Windows API?


   Answer: GDI is a Windows API that provides functions for drawing graphics and text on the screen and printers. It enables developers to create graphical user interfaces and graphics-rich applications.


2. How does GDI handle fonts in graphical applications?


   Answer: GDI uses fonts to render text on the screen. Developers can select a font using the SelectObject function and then use the TextOut or DrawText function to draw text on the screen.


3. What is the purpose of the CreatePen function in GDI?


   Answer: The CreatePen function is used to create a logical pen object with specified attributes, such as color, width, and style. This pen can be selected using the SelectObject function for drawing lines and curves.


4. How does GDI handle color in graphical applications?


   Answer: GDI uses RGB (Red, Green, Blue) values to represent colors. Developers can create solid color brushes using the CreateSolidBrush function to fill shapes with a specific color.


5. Explain the role of the BitBlt function in GDI.


   Answer: The BitBlt function is used for bit-block transfers, allowing efficient copying of image data between devices like screens and bitmaps. It enables fast image drawing and manipulation.


6. What are GDI paths, and how are they used?


   Answer: GDI paths are sequences of lines and curves that define a shape. They are created using functions like BeginPath, LineTo, and CurveTo. Developers can then stroke or fill the path using appropriate GDI functions.


7. How does GDI support printing in Windows applications?


   Answer: GDI provides functions to create printer device contexts and print graphical elements directly to printers. Developers can use similar GDI functions as used for screen drawing but target the printer device context.


8. What is the purpose of the SetPixel function in GDI?


   Answer: The SetPixel function sets the color of a single pixel at a specified location on the screen or a bitmap. It is useful for low-level pixel manipulation tasks.


9. How does GDI handle transparency and blending?


   Answer: GDI supports transparency and blending through the use of alpha blending functions. Developers can set the transparency level and combine images or colors with existing content.


10. Can GDI be used for 3D graphics and hardware-accelerated rendering?


   Answer: No, GDI is primarily designed for 2D graphics and does not support hardware-accelerated rendering or complex 3D graphics. For advanced 3D rendering, developers typically use APIs like DirectX or OpenGL.

The Graphics Device Interface (GDI) is a core component of the Microsoft Windows operating system, responsible for rendering 2D graphics and text on screens and printers. GDI provides a set of functions and data structures that allow developers to create graphical user interfaces, draw shapes, text, and images, and manage graphics resources efficiently. GDI works by using a device context (DC) to represent the graphics output of a particular device, such as a screen or printer. A device context holds information about the device's capabilities and attributes, including the resolution, color depth, and physical size. Developers use GDI functions to draw graphics and text on the device context, and the results are automatically displayed on the corresponding device. One of the primary tasks of GDI is to draw basic geometric shapes, such as lines, rectangles, ellipses, and polygons. Developers can specify the position, size, color, and style of these shapes using GDI functions like LineTo, Rectangle, Ellipse, and Polygon. Additionally, GDI provides various pen and brush styles to customize the appearance of these shapes, allowing for a wide range of artistic possibilities. Text rendering is another critical aspect of GDI. Developers can use GDI functions like TextOut and DrawText to display text on the screen or printer. GDI supports various font styles and sizes, making it possible to create visually appealing text elements in applications. To efficiently manage graphical resources, GDI employs the concept of GDI objects. GDI objects represent graphical elements such as pens, brushes, fonts, bitmaps, and regions. Each GDI object is assigned a unique handle, and developers can create, select, and delete these objects using GDI functions. Proper management of GDI objects is crucial to avoid resource leaks and ensure optimal performance. GDI also offers features like transparency, alpha blending, and image stretching, enabling developers to create visually rich and interactive user interfaces. By using alpha blending, developers can combine images or text with the background, creating smooth transitions and visual effects. The StretchBlt function allows images to be resized and smoothly scaled, ensuring that graphics are displayed correctly on screens with different resolutions. While GDI remains a reliable and straightforward solution for 2D graphics and basic graphical user interfaces, it has limitations when it comes to advanced 3D graphics and hardware-accelerated rendering. For more complex and interactive graphics, developers often turn to modern graphics APIs like DirectX or OpenGL, which support hardware acceleration and sophisticated 3D rendering techniques. In conclusion, the Graphics Device Interface (GDI) is a critical component of Windows, offering a powerful set of functions for 2D graphics, text rendering, and resource management. By using GDI, developers can create visually appealing and interactive graphical applications for a wide range of Windows-based devices. However, for advanced 3D graphics and performance-critical applications, other graphics APIs may be more suitable.