BUG in Canvas Class? - page 2

 

Thanks guys for getting back! Really appreciated.


@Ex Ovo Omnia: Within the last days, I tried really any possible combination you could think of using :: \\ " " etc. to get the image loaded but I never succeeded. So I think there is still a bug inside it. 

I will wait until Doerk posted his example and see if it works for me. If not, I will give up on that.


@Doerk Hilger: Thank you very much. I will wait for your example to try it out!


Enjoy your evening guys...

 
syrvn 0:

Thanks guys for getting back! Really appreciated.


@Ex Ovo Omnia: Within the last days, I tried really any possible combination you could think of using :: \\ " " etc. to get the image loaded but I never succeeded. So I think there is still a bug inside it. 

You don't have to try all combination but to think about what you are doing. You are trying to load a resource as a file, it will never work (See documentation about files and resources). So you have either to modify the Canvas class as proposed by Dirk (so it's no more standard), or find an other way.

I will wait until Doerk posted his example and see if it works for me. If not, I will give up on that.

And as Ovo said, the correct way to reference a resource is by replacing the leading '\\' by '::' 

     can.LoadFromFile("::Images\\dollar.bmp");

Enjoy your evening guys...

I would like to add that you don't have to worry, it's not your fault, a "standard" library should be easier to use, and be correctly documented.
 

I was wrong at one point, copied only the first part of the macro, you really need "::Images" upfront. Sorry for that. Anyway, if you want to stuck with the original, you can derive from CCanvas and do it like show below. The problem with the original is, that are are some bugs more when calculating dimensions. I saw that they added several functions and will update the library soon.

By the way, if you do it like that with the given model, you can also deal with bitmaps that support an alpha channel. 



#include <Canvas\Canvas.mqh>

//+------------------------------------------------------------------+
//| Deriving class CCvanvasX to keep the original                    |
//+------------------------------------------------------------------+
class CCanvasX : public CCanvas
{
   public:
   //+------------------------------------------------------------------+
   //| Load data from resource                                          |
   //+------------------------------------------------------------------+
   bool LoadFromResource(const string filename)
     {
      CFileBin file;
   //--- open file
      if (!ResourceReadImage(filename,m_pixels,m_width,m_height))
         return(false);
      return (true);
     }
};
  
//+------------------------------------------------------------------+
//| Static object                                                    |
//+------------------------------------------------------------------+
CCanvasX can;
#resource "\\Images\\dollar.bmp"
#define RESOURCENAME "::Images\\dollar.bmp"
  
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
  can.CreateBitmapLabel("Dollar",100,100,100,100,COLOR_FORMAT_ARGB_NORMALIZE);
  can.LoadFromResource(RESOURCENAME);
  can.Update();
//---
   return(INIT_SUCCEEDED);
  }
 

Result

 

Hi Doerk,

thank you very much for your example. It works for me as well! Great job!


Two Things:

1. As I understand from the code, you overwrite the LoadFromFile function. Is this what you have also done in your uploaded bug fixed canvas libary? If so, I am wondering why my previous example did not work even though I also tried the ::\\ Approach.


2. I just quickly tried to replace CreateBitmapLabele by CreateBitmap as it uses time an price to place the image. However, it did not work. Maybe it is too late for today and I do not see the point. I get back to it by tomorrow. However, here is the Code I tried:

#include <Canvas\Canvas.mqh>

class CCanvasX : public CCanvas { 

public:

   bool LoadFromResource(const string filename) { 
   
   CFileBin file;
   
   if (!ResourceReadImage(filename,m_pixels,m_width,m_height))
      return(false);
   else
      return true;
   }
};

CCanvasX can;

#resource "\\Images\\dollar.bmp"
#define RESOURCENAME "::Images\\dollar.bmp"

int OnInit() {

//can.CreateBitmapLabel("Dollar",100,100,100,100,COLOR_FORMAT_ARGB_NORMALIZE);
can.CreateBitmap(0,0,"Dollar",TimeCurrent(),1.046,50,50,COLOR_FORMAT_ARGB_NORMALIZE);

can.LoadFromResource(RESOURCENAME);

can.Update();

return(INIT_SUCCEEDED);

}

Anyhow guys, thanks a lot for all of your Support so far!

 

Of course it does not work. You can only use a start time which matches a time of a bar. TimeCurrent() will only match when a new bar starts. When you modify this this way, it will work. I´ve tested it.

Reason: