549 views
in GUI Development by
Hi,

I'm using Canvas object to create my own component and I need an API like setting a pixel at the specified coordinate.

I tried to find it, but it looks like that there is no similiar API in Canvas object.

If there is any other way of setting a pixel, please let me know.

1 Answer

0 votes
by

Hello,

you can use the Canvas' method DrawLine() to draw a line with 1 pixel width. Anyway, trying to compose a complete image by using Canvas and setting pixels one by one will be very inefficient. The Embedded Wizard Graphics Engine pipeline is not optimized to access the pixel individually. This is even not possible on particular target systems like the OpenGL ES. Generally, there are following application cases:

1. You compose the GUI application from views and other GUI components. Embedded Wizatrd optimizes the composition trying to elliminate unnecessary operations.

2. You use the Canvas object and fill it with rectangles, images, text, etc. You benefit from the optimized routines to draw the affected shapes. If your target supports hardware acceleration, it is used here. In fact, the here used functionality is the basement for the view composition mentioned in the item 1 above.

3. You want to create a pixel image. In this case create and fill an Extern Bitmap. With Extern Bitmap you can access and modify the pixel memory of the bitmap directly in the native code (ANSI C). In other words you can calculate and set pixel individually. See also: Displaying dynamically loaded images and Extern Bitmap interface.

Best regards

Paul Banach

by
Hi Paul,

Thanks for your kind reply. It helped me a lot.

Best Regards,

Kangmin
by
Hi Paul

It's been a while since we talk. How have you been?

I have a further question.
Can I use the Canvas's method FillRectangle() to draw pixel one by one?
If yes, DrawLine() vs FillRectangle(), which one is faster(or efficient)?

Please note that I'm using Embedded Wizard V9.30 with i.MX RT1050.
I'd like to what effect PXP(Pixel Pipeline) have.

Best Regards,
Kangmin
by

Hello Kangmin,

thank you I'm fine. I hope you are doing well these days too.

Concerning your question, well, you can draw pixel by using FillRectangle or DrawLine. In fact, you draw 1-pixel large line or rectangle. However, I expect in this case very bad performance. The drawing functions have an overhead resulting from the necessary preparation of the drawing instructions, time needed to trigger the HW (e.g. PXP) and synchronize with the following drawing operations. This approach is thus useful only if you have few pixel to draw.

If you have an application case where you need to compose an image programmatically and none of the Embedded Wizard drawing functions works for you, the recommended approach would be to prepare the image within an Extern Bitmap as explained in my first answer of this thread. With this approach you can directly address the bitmap memory and flexibly set the pixel.

I hope, it helps you further.

Best regards

Paul Banach

by
Hi Paul,

Thank you for your input.

I think my team can handle this.

Many thanks,

Kangmin

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...