Canvas is cool! - page 85

 
Nikolai Semko #:
Unfortunately, in MQL4 there is no possibility to attach a resource as an array. But everything else works.
Of course, it is possible to implement it 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 more dense 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 ex4 file is stored in a compacted format, but not by an order of magnitude less. It is necessary to check exactly.

By the way, I have never been able to insert BMP with alpha channel in MQL4 when the image has transparency like png. It either doesn't show or doesn't compile.

There was a discussion here https://www.mql5.com/en/forum/157832 As a result, it is only suitable for MT5. But it is interesting that BMP exist with alpha channel.

It didn't work with PNG either... or didn't figure out how.


About canvas and scaling, Thanks, I will try it on mq4.

 
Vitaliy Kuznetsov #:

By the way, I have never been able to insert BMP with alpha channel in MQL4, when the image has transparency like png. It is either not shown or not compiled.

There was a discussion here https://www.mql5.com/en/forum/157832 As a result, it is only suitable for MT5. But it is interesting that BMPs exist with alpha channel.

It didn't work with PNG either... or didn't realise how.


About canvas and scaling, Thanks, I'll try it on mq4.

There is no blinking bug in MQL4.
Attached is the mql4 version.

 
Nikolai Semko #:

There is no blinking bug in MQL4.
Attached is the mql4 version.

That's a fitting. Thank you!

 

At first I was happy, but now I am stumped. I can't load a file from outside through settings in the indicator, but not inside the compiled file.

Nikolai Semko, if you have time, please write if it is possible. And if you have an example with setting transparency and file selection, you can help me out.

 
Vitaliy Kuznetsov #:

At first I was happy, but now I am stumped. I can't load a file from outside through settings in the indicator, but not inside the compiled file.

Nikolai Semko, if you have time, please write if it is possible. And if you have an example with setting transparency and file selection, you will help me out.

I don't understand, what is the difficulty to load png as uchar array and then feed it to Png class object.
It's not hard at all to add the LoadPngFromFile(string file_name) method to the Png class. I just didn't set myself such a task, so I didn't implement it. But you can easily cope with it.
h ttps://www.mql5.com/ru/docs/files/filereadarray
Look at the constructor of the Png class, which takes as input an array uchar[] , which contains the whole png file.

*

Oops, I'm stupid. The second constructor that takes a file name has already been implemented. Then I don't see any difficulties at all.

CPng::CPng(string file_path, bool create_canvas = false, int x = 0, int y = 0);
Документация по MQL5: Файловые операции / FileReadArray
Документация по MQL5: Файловые операции / FileReadArray
  • www.mql5.com
FileReadArray - Файловые операции - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Vitaliy Kuznetsov #:

At first I was happy, but now I am stumped. I can't load a file from outside through settings in the indicator, but not inside the compiled file.

Nikolai Semko, if you have time, please write if it is possible. And if you have an example with setting transparency and file selection, you can help me out.

here is a new version of CPng, which has the LoadPngFromFile() function.

Files:
Png.mqh  38 kb
 
Nikolai Semko #:
I don't understand the difficulty in uploading a png

Indeed..., it's not always easy)

Nikolai Semko #:
here is a new version of CPng, which has LoadPngFromFile() function.

Thanks, I will try it

 
Nikolai Semko #:
I didn't understand, what is the difficulty to load png as uchar array and then nurture it to object of Png class.

I've figured out the external PNGs, 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"

... gives 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 theoretically it is possible to write a script that will convert PNG into code and we will put it, say, in MQH and work with them as a part of one container. But I can't write such a script. Picture arrays are a blind forest for me.

 
Vitaliy Kuznetsov #:

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

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

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


Attached an example

Files:
Resurs.mq5  634 kb
 
Vitaliy Kuznetsov #:

Is it even realistic to compile PNG inside a file?

Ask the developers to insert PNG here.

I'm sure they'll agree.