MQL4参考 普通函数 ResourceCreate

ResourceCreate

Creates an image resource based on a data set. There are two variants of the function:
Creating a resource based on a file

bool  ResourceCreate(
   const string      resource_name,       // Resource name
   const string      path                 // A relative path to the file
   );

Creating a resource based on the array of pixels

bool  ResourceCreate(
   const string      resource_name,       // Resource name
   const uint&       data[],              // Data set as an array
   uint              img_width,           // The width of the image resource
   uint              img_height,          // The height of the image resource
   uint              data_xoffset,        // The horizontal rightward offset of the upper left corner of the image
   uint              data_yoffset,        // The vertical downward offset of the upper left corner of the image
   uint              data_width,          // The total width of the image based on the data set
   ENUM_COLOR_FORMAT color_format         // Color processing method
   );

Parameters

resource_name

[in]  Resource name.

path

[in]  Relative path to the file, containing the resource data. If the path is started from "\" (written as "\\"), it is assumed that file path is relative to terminal_data_folder\MQL4\, otherwise it is assumed that file is specified relative to .EX4 program folder.

data[][]

[in]  A one-dimensional or two-dimensional array for creating a complete image.

img_width

[in]  The width of the rectangular image area in pixels to be placed in the resource in the form of an image. It cannot be greater than the data_width value.

img_height

[in]  The height of the rectangular image area in pixels to be placed in the resource in the form of an image.

data_xoffset

[in]  The horizontal rightward offset of the rectangular area of the image.

data_yoffset

[in]  The vertical downward offset of the rectangular area of the image.

data_width

[in]  Required only for one-dimensional arrays. It denotes the full width of the image from the data set. If data_width=0, it is assumed to be equal to img_width. For two-dimensional arrays the parameter is ignored and is assumed to be equal to the second dimension of the data[] array.

color_format

[in]  Color processing method, from a value from the ENUM_COLOR_FORMAT enumeration.

Return Value

Returns true if successful, otherwise false. To get information about the error call the GetLastError() function. The following errors may occur:

  • 4015 - ERR_RESOURCE_NAME_DUPLICATED (identical names of the dynamic and the static resource)
  • 4016 - ERR_RESOURCE_NOT_FOUND (the resource is not found)
  • 4017 - ERR_RESOURCE_UNSUPPORTED_TYPE (this type of resource is not supported)
  • 4018 - ERR_RESOURCE_NAME_IS_TOO_LONG (the name of the resource is too long)

Note

If the second version of the function is called for creating the same resource with different width, height and shift parameters, it does not create a new resource, but simply updates the existing one.

The first version of the function is used for uploading images and sounds from files, and the second version is used only for the dynamic creation of images.

Images must be in the BMP format with a color depth of 24 or 32 bits. Sounds can only be in the WAV format. The size of the resource should not exceed 16 Mb.
 

ENUM_COLOR_FORMAT

Identifier

Description

COLOR_FORMAT_XRGB_NOALPHA

The component of the alpha channel is ignored

COLOR_FORMAT_ARGB_RAW

Color components are not handled by the terminal (must be correctly set by the user)

COLOR_FORMAT_ARGB_NORMALIZE

Color components are handled by the terminal

See also

Resources, ObjectCreate(), ObjectSetString(), OBJPROP_BMPFILE