ResourceCreate

データセットに基づいて画像のリソースを作成します。この関数には 2 つのバージョンがあります。
ファイルに基づいてリソースの作成

bool  ResourceCreate(
  const string      resource_name,       // リソース名
  const string      path               // ファイルへの相対パス
  );

画素の配列に基づいてリソースの作成

bool  ResourceCreate(
  const string      resource_name,      // リソース名
  const uint&       data[],              // 配列としてのデータセット
  uint             img_width,         // 画像リソースの幅
  uint             img_height,         // 画像リソースの高さ
  uint             data_xoffset,       // 画像の左上隅の水平右方向オフセット
  uint             data_yoffset,       // 画像の左上隅の鉛直オフセット
  uint             data_width,         // データセットに基づいた画像の全体の幅
  ENUM_COLOR_FORMAT color_format         // 色処理方法
  );

パラメータ

resource_name

[in]  リソース名

data[][]

。[in]  完全な画像を作成するための 1 次元または 2 次元の配列。

img_width

[in]  画像としてリソースに配置される矩形の画像領域のピクセルで表された幅。data_width を超すことは出来ません。

img_height

[in]  画像としてリソースに配置される矩形の画像領域の高さ(ピクセル単位)。

data_xoffset

[in]  画像の矩形領域の水平右方向オフセット。

data_yoffset

[in]  画像の矩形領域の縦の下方のオフセット。

data_width

[in]  1 次元配列のみで必要。データセットから画像の全幅を表します。data_width=0 の場合、値が img_width と等しいとみなされます。2 次元配列の場合、パラメータは無視され、data[] 配列の第 2 次元に等しいと仮定されます。

color_format

[in]  色処理方法で ENUM_COLOR_FORMAT 列挙から選ばれます。

戻り値

成功の場合は true、それ以外の場合は false 。エラー情報を取得するには、GetLastError() 関数が呼ばれます。次のエラーが発生可能です。

  • 4015 – ERR_RESOURCE_NAME_DUPLICATED (同名の動的リソースと静的リソース)
  • 4016 – ERR_RESOURCE_NOT_FOUND (リソースが見つからない)
  • 4017 – ERR_RESOURCE_UNSUPPORTED_TYPE (この種類のリソースのサポートが不在)
  • 4018 – ERR_RESOURCE_NAME_IS_TOO_LONG (リソース名が長すぎる)

注意事項

関数の 2 番目のバージョンが、異なる幅、高さ、及びシフトパラメータを使用して同じリソースを作成するために呼び出された場合は、新しいリソースは作成されず、単に既存のものが更新されます。

関数の最初のバージョンは、ファイルから画像や音声をアップロードするために使用され、2 番目のバージョンは、画像を動的に作成するために使用されます。

画像は24ビットまたは 32 ビットの色深度を持つ BMP 形式でなければなりません。サポートされているサウンド形式は WAV のみです。リソースのサイズは、16 MBを超えてはなりません。
 

ENUM_COLOR_FORMAT

識別子

説明

COLOR_FORMAT_XRGB_NOALPHA

アルファチャンネルの成分は無視されます。

COLOR_FORMAT_ARGB_RAW

色成分は端末によって処理されません(ユーザが正しく設定する必要があります)。

COLOR_FORMAT_ARGB_NORMALIZE

色成分は端末によって処理されます。

Example:

//+------------------------------------------------------------------+
//| Update graphical resource data                                   |
//+------------------------------------------------------------------+
void Update(const string res_name,const uint &pixel_data[],const uint width,const uint height,const bool redraw)
 {
//--- leave if zero dimensions are passed
  if(width==0 || height==0)
    return;
//--- Update resource data and redraw the chart
  if(ResourceCreate(res_name,pixel_data,width,height,0,0,0,COLOR_FORMAT_ARGB_NORMALIZE) && redraw)
    ChartRedraw();
 }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
 {
//--- declare the parameters of the graphical resource
  string rc_name="Resource";
  uint   rc_width=100;
  uint   rc_height=100;
  uint   rc_data[];
  uint   rc_size=rc_width*rc_height;
 
  ResetLastError();
//--- set the size of the pixel array
  if(ArrayResize(rc_data,rc_size)!=rc_size)
    {
    Print("ArrayResize() failed. Error code: ",GetLastError());
    return;
    }
//--- fill the pixel array with a transparent color and create a graphical resource based on it
  ArrayInitialize(rc_data,0x00FFFFFF);
  if(!ResourceCreate(rc_name,rc_data,rc_width,rc_height,0,0,0,COLOR_FORMAT_ARGB_NORMALIZE))
    {
    Print("ResourceCreate() failed. Error code: ",GetLastError());
    return;
    }
  Print("Size of created recource array: ",rc_data.Size());
 
//--- check the created graphical resource.
//--- get the time and price data of the current bar
  MqlTick tick={};
  if(!SymbolInfoTick(Symbol(),tick))
    {
    Print("SymbolInfoTick() failed. Error code: ",GetLastError());
    return;
    }
//--- create the Bitmap object using the coordinates of the last tick price and time
  string obj_name="Bitmap";
  if(!ObjectCreate(0,obj_name,OBJ_BITMAP,0,tick.time,tick.bid))
    {
    Print("ObjectCreate() failed. Error code: ",GetLastError());
    return;
    }
//--- set the width and height of the created bitmap object equal to the width and height of the graphical resource.
//--- set the object anchor point to its center.
  ObjectSetInteger(0,obj_name,OBJPROP_XSIZE,rc_width);
  ObjectSetInteger(0,obj_name,OBJPROP_YSIZE,rc_height);
  ObjectSetInteger(0,obj_name,OBJPROP_ANCHOR,ANCHOR_CENTER);
//--- specify the previously created graphical resource for the bitmap object as an image file
//--- in this case, in order to indicate the name of the graphical resource used, we need to add "::" before its name
  ObjectSetString(0,obj_name,OBJPROP_BMPFILE,"::"+rc_name);
 
//--- set the DodgerBlue color with the transparency of 200
  uint clr=ColorToARGB(clrDodgerBlue,200);
//--- fill the entire array of pixels of the graphical resource with the set color
  ArrayInitialize(rc_data,clr);
//--- update the graphical resource data
  Update(rc_name,rc_data,rc_width,rc_height,true);
 }

参照

リソースObjectCreate()ObjectSetString()OBJPROP_BMPFILE