Canvas is cool! - page 86

 
Aleksandr Slavskii #:

You can insert a file as an array and then access that array.


Attached example

Yes, by the way, this works. I didn't know about this possibility. Thanks!
But the size of mq4 or mqh file will be 5 times larger than the png file itself. But it is quite a working option, because it does not affect the size of the ex4 file itself. (it will be the same as ex5 file).

fxsaber #:

Ask developers to insert PNG here.

I'm sure they will agree.

I doubt that any wishes and requests will be implemented for MT4, especially when it is already announced that MT4 support will end soon.

 
Vitaliy Kuznetsov #:

External PNGs sorted out, loading, scaling, transparency works. But...

Is it even realistic to compile a PNG inside a file?

The standard functionality ...

#resource "\\Files\\123.png"

string nam_img = "::Files\\123.png"

... generates a compilation error

I didn't get into the fact that the software works with an external file, but how to make the whole final product to be one file?

Otherwise the practical sense of such a feature is lost. I have not tried it in MT5. In MT4 there is a connection error.


P.S. I assume that it is theoretically possible to write a script that will convert PNG into code and we will put it, say, in MQH and work with them in one container. But I can't write such a script. Picture arrays are a blind forest for me.

Apart from what Alexander suggested (through inserting uchar[] array), there is also a crutch method through pseudo BMP, which I have already talked about

Forum on trading, automated trading systems and testing trading strategies

Canvas is cool!

Nikolai Semko, 2023.09.25 17:09

Unfortunately, in MQL4 there is no possibility to attach a resource as an array. But everything else works.
Of course, it can be implemented through hard tambourines. For example, insert a PNG image into a BMP file, i.e. add a BMP header to the beginning of the png, and pass the png itself as a bmp image (i.e. if you open such a BMP, there will be a noise of coloured pixels of different transparency). And then attach this "bmp file" as a resource in MQL4. This may be necessary for the market, so that ex4 already contains an image of a denser png format.
For reference: png is about 10 times smaller than the same BMP image without loss of quality, in addition supporting full transparency.
True bmp resource in ex5(ex4) file is stored in a compacted format, but not by an order of magnitude less. It is necessary to check exactly.

You can write a script that performs such conversion from png to bmp (the size of the pseudo-image of such a file will be equal in width to the size of the png file itself, and 1 pixel in height).
But you can do with another algorithm: Convert PNG with transparency into a real BMP with transparency and attach it via a resource. The size of ex4 file will be slightly larger than the size with png file, because in ex4 the bmp file resource is stored in packed format. I checked - the increase of ex4 size with bmp will be 10-30% more than ex4 with the same image in png format.

Personally, I would prefer the variant suggested by Slavsky. To put a separate uchar array in a separate mqh file, which will contain the png file itself, and then insert it into the code via an include, so that the giant array does not clutter the code.
Moreover, the advantage of this method is that you do not need to put any graphic files in the MQL4 sandbox, as in the case of resources.

 
fxsaber #:

Ask the developers to insert a PNG here.

I'm sure they'll agree.

Let's add it to MQL5.

 
Aleksandr Slavskii #:

You can insert a file as an array and then access that array.

Attached example

amazing, how long has this "Insert" menu been in ME? :O

live and learn...

 
Renat Fatkhullin #:

Let's add it to MQL5.

Market shows that all products are duplicated for both platforms. Most likely, they will not use the non-cross-platform variant, but will remain sitting on BMP, unfortunately.


You can attach any file in MQL5 even now.

// resource variables are supported by MQL5 language only
#resource "\\Files\\Picture.png" as uchar PNGBytes[]
Such attachment will create a static array with data, not a resource. In the second case, it seems to be available from other EX4/5.
 
Nikolai Semko #:
Convert PNG with transparency to real BMP with transparency and attach it via resource.

This option does not work in MT4, because BMP with alpha channel is attached but not displayed.

fxsaber #:

Market shows that all products are duplicated for both platforms. Most likely will not use the non cross-platform variant, and will remain sitting on BMP, unfortunately.

I think PNG has already become cross-platform. It already works with external files. Examples above from Nikolay.

Aleksandr Slavskii #:

You can insert a file as an array and then access this array.

Indeed, it does. I was directly surprised.


It remains to try to realise in Canvas all the stuff with rubberiness, transparency and that's it - a small mq4 miracle is ready.

Of course, this is done for cross-platform. Because on MT4 - BMP, and on MT5 - PNG. No good. Everything should be PNG.

 
Vitaliy Kuznetsov #:

It remains to try to implement in Canvas the whole rubbery, transparent thing and that's it - a small mq4 miracle is ready.

So everything is already ready. You can take an example test from the PNG library. Only the line with the resource

#resource "//Images//icons.png" as uchar png_data[]

change it to the line

#include <PNG\iconspng.mqh>

where in the iconspng.mqh file we insert the png_data[] array.

Only it is necessary to remember that in MT4 it is important to output all costly calculations from OnChartEvent to the timer, otherwise it will lag terribly. Purely MQL4 bullshit.
I will now drop a non-lagging version.


 
Nikolai Semko #:

I'm about to upload a non-lagging version.

Yeah, it doesn't even lag if the CPU is in "best perfomance" mode.


Files:
MQL4.ZIP  576 kb
 
Andrey Dik #:

amazing, how long has this "Insert" menu in ME been there? :O

live and learn...

Among my files, where I experimented with such file insertion, I found a file created in November 2019. I was interested in it even earlier. Unfortunately, I have not found the script where the image file was saved from such an array.

 
Alexey Viktorov #:

Among my files, where I experimented with such file insertion, I found a file created in November 2019. I was interested in it even earlier. Unfortunately I didn't find the script where the image file was saved from such an array.


super! handy feature.
Although, inserting ex5 could be even more convenient if the declarations of exported functions were displayed.
Reason: