Table of contents
1.
Introduction
2.
Syntax
3.
Public Methods
4.
Requirements
5.
CImage::AlphaBlend
6.
CImage::Attach
7.
CImage::BitBlt
8.
CImage::Create
9.
CImage::CreateEx
10.
Frequently Asked Questions
10.1.
What is a utility class?
10.2.
What is ATL?
10.3.
What is MFC?
10.4.
What are the classes shared by MFC and ATL?
11.
Conclusion
Last Updated: Mar 27, 2024
Easy

UtilityClass CImage

Author Shubham Das
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

CImage is a class which is present in the ATL(Active Template Library). The ATL(Active Template Library) is a set of template-based C++ classes.

utilityclass cimage

CImage gives bitmap support. It has the ability to load and save images JPEG (Joint Photographic Experts Group), BMP (Bitmap Image file), PNG (Portable Network Graphics), and GIF (Graphics Interchange Format) formats.

Syntax

Now, let's have a look what is the syntax for using CImage.

class CImage

Public Methods

Name of the method Description
CImage::AlphaBlend It displays bitmaps that have transparent or semitransparent pixels.
CImage::Attach It attaches an HBITMAP to the CImage object. Can be used with either DIB section bitmaps or non-DIB section bitmaps.
CImage::BitBlt It copies a bitmap from the source device context to this current device context.
CImage::Create It creates a DIB section bitmap and attaches it to the previously constructed CImage object.
CImage::CreateEx It is similar to the CImage::Create creates a DIB section bitmap but with additional parameters and attaches the same to the previously constructed CImage object.
CImage::Destroy It detaches the bitmap from the CImage object and destroys the bitmap.
CImage::Detach It detaches the bitmap from a CImage object.
CImage::Draw It copies a bitmap into a destination rectangle from the source rectangle. Compresses the bitmap or draw stretches to fit the dimensions(pixels) of the destination rectangle, if necessary, and transparent colours and handles alpha blending.
CImage::GetBits It retrieves a pointer to the actual pixel values of the bitmap.
CImage::GetBPP It retrieves the bits per pixel.
CImage::GetColorTable It retrieves RGB(red, green, blue) values (RGB) color values from the range of entries in the color table.
CImage::GetDC It retrieves the device context into which the current bitmap is selected.
CImage::GetExporterFilterString It finds the available image formats and their descriptions.
CImage::GetHeight It retrieves the height of the current image in pixels.
CImage::GetImporterFilterString It finds the available image formats and their descriptions.
CImage::GetMaxColorTableEntries It retrieves the maximum number of entries in the colour table.
CImage::GetPitch It retrieves the pitch of the current image, in bytes.
CImage::GetPixel It retrieves the color of the pixel specified by x and y.
CImage::GetPixelAddress It retrieves the address of a given pixel.
CImage::GetTransparentColor It retrieves the position of the transparent colour in the colour table.
CImage::GetWidth It retrieves the width of the current image in pixels.
CImage::IsDIBSection It determines if the attached bitmap is a DIB section.
CImage::IsIndexed It indicates that a bitmap's colours are mapped to an indexed palette.
CImage::IsNull It indicates if a source bitmap is currently loaded.
CImage::IsTransparencySupported It indicates whether the application supports transparent bitmaps.
CImage::Load It loads an image from the specified file.
CImage::LoadFromResource It loads an image from the specified resource.
CImage::MaskBlt It combines the colour data for both the destination and source bitmaps using the raster operation specified mask.
CImage::PlgBlt It performs a bit-block transfer from a rectangle in the source device context into a //gm(parallelogram) in the destination device context.
CImage::ReleaseDC It releases the device context that was retrieved with the CImage::GetDC.
CImage::ReleaseGDIPlus Releases resources used by GDI+. Need to be called to free the resources created by the global CImage object.
CImage::Save It saves an image as the specified type. Save cannot specify image options.
CImage::SetColorTable It sets red, green, and blue RGB) colour values in a range of entries in the colour table of the DIB section.
CImage::SetPixel It sets the pixel at the specified coordinates to the specified color.
CImage::SetPixelIndexed It sets the pixel at the specified coordinates at the specified index of the palette to the color.
CImage::SetPixelRGB It sets the pixel at the specified coordinates to the specified RGB(red, green, and blue) value.
CImage::SetTransparentColor It sets the index of the color to be treated as transparent. Only one colour in a palette can be transparent.
CImage::StretchBlt It copies a bitmap from a source rectangle into the destination rectangle, compressing or stretching the bitmap to fit the dimensions(pixels) of the destination rectangle, if necessary.
CImage::TransparentBlt It copies a bitmap with transparent colour to the current device context from the source device context.

Requirements

The required header is atlimage.h

CImage::AlphaBlend

It displays bitmaps that have transparent or semitransparent pixels.

 

BOOL AlphaBlend(
    HDC hDestDC,
    int xDest,
    int yDest,
    BYTE bSrcAlpha = 0xff,
    BYTE bBlendOp = AC_SRC_OVER) const throw();

BOOL AlphaBlend(
    HDC hDestDC,
    const POINT& pointDest,
    BYTE bSrcAlpha = 0xff,
    BYTE bBlendOp = AC_SRC_OVER) const throw();

BOOL AlphaBlend(
    HDC hDestDC,
    int xDest,
    int yDest,
    int nDestWidth,
    int nDestHeight,
    int xSrc,
    int ySrc,
    int nSrcWidth,
    int nSrcHeight,
    BYTE bSrcAlpha = 0xff,
    BYTE bBlendOp = AC_SRC_OVER);

BOOL AlphaBlend(
    HDC hDestDC,
    const RECT& rectDest,
    const RECT& rectSrc,
    BYTE bSrcAlpha = 0xff,
    BYTE bBlendOp = AC_SRC_OVER);
You can also try this code with Online C++ Compiler
Run Code


It returns non-zero if successful, otherwise zero.

CImage::Attach

It attaches hBitmap to a CImage object.

 

void Attach(HBITMAP hBitmap, DIBOrientation eOrientation = DIBOR_DEFAULT) throw();
You can also try this code with Online C++ Compiler
Run Code

CImage::BitBlt

It copies a bitmap from the source device context to this current device context.

 

BOOL BitBlt(
    HDC hDestDC,
    int xDest,
    int yDest,
    DWORD dwROP = SRCCOPY) const throw();

BOOL BitBlt(
    HDC hDestDC,
    const POINT& pointDest,
    DWORD dwROP = SRCCOPY) const throw();

BOOL BitBlt(
    HDC hDestDC,
    int xDest,
    int yDest,
    int nDestWidth,
    int nDestHeight,
    int xSrc,
    int ySrc,
    DWORD dwROP = SRCCOPY) const throw();

BOOL BitBlt(
    HDC hDestDC,
    const RECT& rectDest,
    const POINT& pointSrc,
    DWORD dwROP = SRCCOPY) const throw();
    
You can also try this code with Online C++ Compiler
Run Code


It returns non-zero if successful, otherwise zero.

CImage::Create

It creates a CImage bitmap and attaches it to the previously constructed CImage object.

 

BOOL Create(
    int nWidth,
    int nHeight,
    int nBPP,
    DWORD dwFlags = 0) throw();
    
You can also try this code with Online C++ Compiler
Run Code


It returns non-zero if successful, otherwise zero.

CImage::CreateEx

It creates a CImage bitmap and attach it to the previously constructed CImage object.

 

BOOL CreateEx(
   int nWidth,
   int nHeight,
   int nBPP,
   DWORD eCompression,
   const DWORD* pdwBitmasks = NULL,
   DWORD dwFlags = 0) throw();
   
You can also try this code with Online C++ Compiler
Run Code


It returns TRUE if successful, otherwise FALSE.


Alright! Now we hope you understand the UtilityClass-CImage.

Frequently Asked Questions

What is a utility class?

Utility class is a class that has only stratic methods that perform certain operations on the objects passed as parameters. Utility classes generally have no state.

What is ATL?

ATL stands for the Active Template Library. ATL is a set of template-based C++ classes developed by Microsoft, and had the intentions to simplify the programming of Component Object Model objects.

What is MFC?

MFC stands for Microsoft Foundation Class Library. MFC is a C++ object-oriented library for developing desktop applications for Windows. MFC was introduced by Microsoft in 1992 and quickly gained widespread use.

What are the classes shared by MFC and ATL?

The classes that are shared by MFC and ATL are CFileTime, CFileTimeSpan, CFixedStringT, CImage, COleDateTime, COleDateTimeSpan, CPoint, CRect, CSimpleStringT, CSize, CStrBufT, CStrBufT, CStringT, CTime, CTimeSpan, and IAtlStringMgr.

Conclusion

In this article, we discussed the UtilityClass-CImage. We hope this blog on UtilityClass-CImage was helpful. You can also refer to other similar articles.


You may refer to our Guided Path on Code Studios for enhancing your skill set on DSACompetitive ProgrammingSystem Design, etc. Check out essential interview questions, practice our available mock tests, look at the interview bundle for interview preparations, and so much more!

Happy Learning Ninja!

Live masterclass