BUG in Canvas Class?

To add comments, please log in or register
syrvn 0
134
syrvn 0  

Hiya,


I recently asked about the canvas class: https://www.mql5.com/en/forum/216442


I spent quite some time now to get into this class and its functions, however I am still struggling to get a BMP drawn. I found the following post: https://www.mql5.com/en/forum/157832#comment_3808455

At the very end of the post, there is a guy - xtrader68 - who had the same issues. I reproduced his example and also used #resource as adivsed below by JPS1 . Here is my Code:

#include <Canvas/Canvas.mqh>

#resource "\\Images\\dollar.bmp";

CCanvas can;

int OnInit() {

    if(!can.CreateBitmapLabel(0,0,"dollar",20,20,200,200))
    {
         Print("Error creating histogram chart: ",GetLastError());
         return(-1);
    }

    can.LoadFromFile("::\\Images\\dollar.bmp");
    can.FillCircle(100,100,20,clrDarkGoldenrod);

   can.Update();
   ChartRedraw();

   return(INIT_SUCCEEDED);
}



The result looks as follows:

CAnvas

As you can see, the CreateBitmapLabel is correctly drawn and also the filled circle. However, the Bitmap is missing. It also says: File not found as highlighted in yellow.

However, the #resource "\\Images\\dollar.bmp"; seems to work as when I change the path to e.g. Images\\Dollar.bmp when I compile the file it says: cannot open resource file.....


I also tried the CreateBitmap function as follows:

#include <Canvas/Canvas.mqh>

#resource "\\Images\\dollar.bmp";

CCanvas can;

int OnInit() {
   
    if(!can.CreateBitmap("test",TimeCurrent(),1.047,200,200)) {
       Print("Error creating test chart: ",GetLastError());
       return(-1);
    }

    can.LoadFromFile("::\\Images\\dollar.bmp");
    can.FillCircle(100,100,20,clrDarkGoldenrod);

    can.Update();
    ChartRedraw();

    return(INIT_SUCCEEDED);
}


Resulting in:

can2

As you can see I also get the file not found message but there is a red square being drawn into the Chart at TimeCurrent()  and set price. However it seems that the size of 200,200 is not used as the square is quite small.


Here is also my tree structure:

tree



I start believing that there is a BUG in the canvas class as I tried pretty much everything to get this simple example to work.

Is anyone willing to try this example to see whether it works on a different PC/Notebook. 

It is also very much appreciated if someone could post a simple working example inclusive a screenshot of the graph showing a BMP file printed so that I can try reporducing a real working example.


Thank you very much in advance!

Drawing Shapes/Objects using the Canvas Class
Drawing Shapes/Objects using the Canvas Class
  • 2017.09.27
  • www.mql5.com
Folks! I looked at the Canvas class to use its power for simplified drawing of shapes and objects...
Sergey Golubev
Moderator
106126
Sergey Golubev  
syrvn 0
134
syrvn 0  
Sergey Golubev:

Sure! changed it :-)
Doerk Hilger
1062
Doerk Hilger  

Its a bug in your way of thinking ;)

First of all, look for my bugfix of CCanvas.mqh at the library and replace it. 

Reason: You try to load an image from the folder images, but you are in tester, so you need tester/images. Therefore and for reasons of distribution, you should always deal with resources.

Bind your image as resource, and load this with the replacement of CCanvas - cause the original wont do it - but in this case you dont need to deal with tester/images, because your bitmap is loaded while compiling from the normal images folder and not from the tester/images folder. And you dont need to distribute your image when you copy your ea to another installation of MT.

syrvn 0
134
syrvn 0  

Hi Doerk,

first of all, thanks for getting back to me.

Secondly, I replaced my Canvas.mqh and Rect.mqh by your Library:

canvaslib


Thirdly, I am not entirely sure, whether I got your answer right but once replaced the old Canvas.mqh, the Image should actually have been loaded, shouldn't it? 

You said: "Bind your Image as resource, and..."  Isn't it what I was doing with the following code snippet already?: 

#resource "\\Images\\dollar.bmp";


When I re-run both Code examples with your new canvas.mqh, I still get no Images....


I also added the dollar.bmp to the following 3 Folders:

img1

img2

img3


Apart from that, I realized that your update / bug fix of the canvas class is about a year ago. Why the hell, is MetaQuotes not including this in their original MT5 Version?!?!?

I spent days breaking my head why this is not working and now it turns out to be a bug known for a year already. hm...

Doerk Hilger
1062
Doerk Hilger  

... because they never replace any bugs in the library files. Sad but true. The bugs in simple CRect are some years old in the meanwhile.

Whats the code now when you call LoadFromFile? Just that piece ...

Doerk Hilger
1062
Doerk Hilger  

And where is the BMP from? Not all headers are accepted ...

Doerk Hilger
1062
Doerk Hilger  

if you define

#resource "\\Images\\DH\\SFX.bmp"

then your call must be

can.LoadFromFile("DH\\SFX.bmp");
syrvn 0
134
syrvn 0  
Well, yeah, that is really sad. why the heck would they?! However back to the original question. I adjusted my code as follows:


#include <Canvas/Canvas.mqh>

#resource "\\Images\\dollar.bmp";

CCanvas can;

int OnInit() 
{
     if(!can.CreateBitmapLabel(0,0,"dollar",20,20,200,200))
     {
          Print("Error creating histogram chart: ",GetLastError());
          return(-1);
     }

     can.LoadFromFile("dollar.bmp");

     can.Update();

     ChartRedraw();

     return(INIT_SUCCEEDED);
}

The image "dollar.bmp" is the original blue yello dollar Image coming with the Installation of the MT5 in the following Folder:

img4

From 

can.LoadFromFile("dollar.bmp");

I removed the \\Images\\ part as provided in your example.

In my opinion, if the library is bug free, the image now should appear, but it doesn't. Same with just using CreateBitmap.

@Doerk: maybe you are willing enough to quickly produce a working example at your PC and copy paste it here including a screenshot from the Chart and using the standard dollar.bmp Image.

Ex Ovo Omnia
3360
Ex Ovo Omnia  

When using resources, I would type "::Images\\dollar.bmp" rather than "::\\Images\\dollar.bmp".

Doerk Hilger
1062
Doerk Hilger  

Its not a question about "would", its a question about what works and not. I use this since I can think with success and copied this from a working code.

I am not at home at the moment, it will take a bit til I can post the requested sample, sorry.

12
To add comments, please log in or register