Can not get bitmap loaded

 

Hello, 

when i create a bitmap

   if(!ObjectCreate(chart_ID,name,OBJ_BITMAP,sub_window,time,price))
     {
      Print(__FUNCTION__,
            ": failed to create a bitmap in the chart window! Error code = ",GetLastError());
      return(false);
     }
//--- set the path to the image file
   if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,file))
     {
      Print(__FUNCTION__,
            ": failed to load the image! Error code = ",GetLastError());
      return(false);
     }

the bitmap is shown, no problem.

The parameter file has value

\\images\\long.bmp

This works!


When i use 

CCanvas::LoadFromFile(file)

This works not, because a CFIle::Open(file) fails with 5002 "File not found"

or when i pass 

images\\long.bmp

i get error "5004 Can not open file"

When using:

uint BMP[];
bool bret=ResourceReadImage( file,BMP,width,height);

i get error 4068 "Resource not found".

The file is definitely there. (The first solution works).


My question:

How to load a bitmap file ? 

Thank you

 

I could manage to show the bitmap as background of a CCanvas class:

// delcare resource. This is important
#resource  "\\Images\\long.bmp"

// create canvas
int width=100;
int height=100;
string cv_name="cv1";
CCanvas* cv=new CCanvas;            
string bmp="::Images\\long.bmp";
ResetLastError();
// create the canvas
bool bret=cv.CreateBitmapLabel(cv_name,10,10,width,height,COLOR_FORMAT_XRGB_NOALPHA);
// set the bitmpa (CCanvas::LoadFromFile fails)
if(!ObjectSetString(_chart_id,cv_name,OBJPROP_BMPFILE,bmp))
{
  Print(__FUNCTION__,
                ": failed to load the image! Error code = ",GetLastError());
  
}

Important: The bitmap should not have alpha channel.

Unfortunately, when i do text out on this canvas

cv.TextOut(50,50,"Test Text",0x00FF00,0);

This text is invisble.

How to draw text over the canvase image ?

Nikolai, thank you for your example. But also in your example, TextOut works not.

 
chinaski:

I could manage to show the bitmap as background of a CCanvas class:

Important: The bitmap should not have alpha channel.

Unfortunately, when i do text out on this canvas

This text is invisble.

How to draw text over the canvase image ?

Nikolai, thank you for your example. But also in your example, TextOut works not.

In my example, there is an alpha channel, so you need to take care that the alpha channel of the text color is not zero or change your bitmap to COLOR_FORMAT_XRGB_NOALPHA..

You are using a completely transparent color.

Alpha channel is the most significant byte.

cv.TextOut(50,50,"Test Text",0xFF00FF00,0);

In my example, to remove the alpha channel, you need to reinitialize an instance named Canvas in OnInit.

   delete Canvas;
   Canvas= new iCanvas(0,0,0,"iCanvas",0,0,COLOR_FORMAT_XRGB_NOALPHA);
But then forget about the ability to change transparency.