Jump to content

wpReadImageFile

From EDM2
Revision as of 04:36, 17 November 2025 by Martini (talk | contribs) (Created page with "{{DISPLAYTITLE:wpReadImageFile}} This method is specific to Version 4, or higher, of the OS/2 operating system. This instance method reads the image data for the image file and stores it in the instance data for the object. If the image data has already been read, this method simply returns **TRUE**. It does not refresh the image data. ==Syntax== _wpReadImageFile(somSelf) ==Parameters== ;''somSelf'' (WPBitmap *) - input :Pointer to the object on which the method...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This method is specific to Version 4, or higher, of the OS/2 operating system.

This instance method reads the image data for the image file and stores it in the instance data for the object. If the image data has already been read, this method simply returns **TRUE**. It does not refresh the image data.

Syntax

_wpReadImageFile(somSelf)

Parameters

somSelf (WPBitmap *) - input
Pointer to the object on which the method is being invoked.
Points to an object of class WPBitmap.

Returns

rc (BOOL32) - returns
Success indicator.
  • TRUE Successful completion.
  • FALSE Error occurred.

How to Override

This method must be overridden by any subclass of **WPImageFile**.

Usage

This method reads the image data from the image data file and converts it to the format used for an OS/2 Bitmap. This method stores the data in a buffer pointed to by the instance data for the object. Various WPImageFile methods call the **wpReadImageFile** method to read the data from an image file and convert it to a bitmap.

Example Code

#define INCL_WINWORKPLACE
#include <os2.h>

WPBitmap *somSelf; /* Pointer to the object on which the method is being invoked. */
BOOL32 rc; /* Success indicator. */

rc = _wpReadImageFile(somSelf);

Remarks

In the implementation of the WPBitmap class in the Workplace Shell, the **wpReadImageFile** method reads the data from the image file, extracts the bitmap that most closely matches the characteristics of the display, and saves the data associated with that image. For any other image type, the **wpReadImageFile** method should read the data from the image file, select the appropriate image (if the file can contain images for multiple resolution displays), and convert the image data to bitmap format.

Example Code

This example shows a simplified version of the code in the WPBitmap object class. This example assumes that the image file only contains a single image and it is already in bitmap format.

SOM_Scope BOOL32 bmp_wpReadImageFile(WPBitmap *somSelf)
{
  WPBitmapData *somThis = WPBitmapGetData(somSelf);

  CHAR szFileName[CCHMAXPATH];
  HFILE hFile = NULLHANDLE;
  ULONG ulAction;
  FILESTATUS3 FileStatus;
  ULONG ulFileSize;
  PBYTE pBitmapData = NULL;
  APIRET RC;
  ULONG ulBytesRead;
  PBITMAPFILEHEADER pbfh;

  /* If the data has already been read, just return  */
  if(_pBitmapData)
  {
    return TRUE;
  }

  /* Find the bitmap data file
   */
  _wpQueryFilename(somSelf, szFileName, TRUE);

  /* Open the file and find out how big it is  */
  if (DosOpen(szFileName,
              &hFile,
              &ulAction,
              0L,
              FILE_NORMAL,
              FILE_OPEN,
              OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
              NULL))
  {
    return FALSE;
  }

  if (DosQueryFileInfo(hFile,
                       FIL_STANDARD,
                       &FileStatus,
                       sizeof(FileStatus)))
  {
    DosClose (hFile);
    return FALSE;
  }

  /* Allocate space for a buffer large enough to contain the entire file */
  ulFileSize = FileStatus.cbFile;
  pBitmapData = _wpAllocMem(somSelf,ulFileSize,FALSE);
  if (!pBitmapData)
  {
    DosClose (hFile);
    return FALSE;
  }

  /* Read the file into the buffer  */
  RC = DosRead (hFile, pBitmapData, ulFileSize, &ulBytesRead);
  DosClose(hFile);
  hFile = NULLHANDLE;
  if (RC || (ulBytesRead != ulFileSize))
  {
    _wpFreeMem (somSelf,pBitmapData);
    return FALSE;
  }

  /* Make sure the bitmap header has a valid type code and the header
   * fits within the file    */
  pbfh = (PBITMAPFILEHEADER) pBitmapData;
  if (pbfh->usType != BFT_BMAP ||
      (PCH)pbfh + pbfh->cbSize > pBitmapData + ulFileSize)
  {
    _wpFreeMem(somSelf,pBitmapData);
    return FALSE;
  }

  /* Save the bitmap data and exit    */
  _pBitmapData = pBitmapData;
  _ulBitmapDataSize = ulFileSize;
  return TRUE;
}

Related Methods