Emwin image draw

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Hello,

      there maybe a way to copy a bitmap structure and change XSize to a half of original size, something like this:

      C Source Code: Main.c

      1. #include "DIALOG.h"
      2. #include "string.h"
      3. // Original bitmap structure (see Image.c in attach)
      4. extern GUI_CONST_STORAGE GUI_BITMAP bmImage;
      5. // Bitmap structure for a half
      6. GUI_BITMAP bmhalfImage;
      7. void MainTask(void) {
      8. GUI_Init();
      9. WM_MULTIBUF_Enable(1);
      10. GUI_SetBkColor(GUI_LIGHTGRAY);
      11. GUI_Clear();
      12. // Copy bitmap structure
      13. memcpy(&bmhalfImage, &bmImage, sizeof(bmImage));
      14. // Change XSize
      15. bmhalfImage.XSize = 100;
      16. // Draw original bitmap
      17. GUI_DrawBitmap(&bmImage, 50, 50);
      18. // Draw half bitmap
      19. GUI_DrawBitmap(&bmhalfImage, 50, 200);
      20. while(1)
      21. {
      22. GUI_Delay(50);
      23. }
      24. }
      Display All

      As far as I understand it is working with uncompressed bitmaps.

      Maybe a way better is to use memory devices:

      C Source Code: Main.c

      1. #include "DIALOG.h"
      2. // Original bitmap structure (see Image.c in attach)
      3. extern GUI_CONST_STORAGE GUI_BITMAP bmImage;
      4. // Memory device for a half bitmap
      5. GUI_MEMDEV_Handle hMem;
      6. void MainTask(void) {
      7. GUI_Init();
      8. WM_MULTIBUF_Enable(1);
      9. GUI_SetBkColor(GUI_LIGHTGRAY);
      10. GUI_Clear();
      11. // Create memory device with a half size of the image
      12. hMem = GUI_MEMDEV_Create(0, 0, 100, 100);
      13. // Select memory device for drawing
      14. GUI_MEMDEV_Select(hMem);
      15. // Draw original bitmap in memory device
      16. // This ends up with memory device contains half of the image
      17. GUI_DrawBitmap(&bmImage, 0, 0);
      18. // Select LCD screen for drawing
      19. GUI_MEMDEV_Select(0);
      20. // Draw original bitmap
      21. GUI_DrawBitmap(&bmImage, 50, 50);
      22. // Draw half bitmap from memory device
      23. GUI_MEMDEV_CopyToLCDAt(hMem, 50, 200);
      24. while(1)
      25. {
      26. GUI_Delay(50);
      27. }
      28. }
      Display All

      Alex.
      Files
      • Image.zip

        (2.72 kB, downloaded 14 times, last: )
    • Hello,

      Thanks for the reply. I tried the above method and the image displays but is jumbled up.
      when i give bmhalfImage.XSize = 100; the image does not display properly but when i change it to
      bmhalfImage.XSize = 200; i.e. original size the whole image is displayed properly.
      I am currently using above first method for displaying the image.

      I want the image to be displayed properly but only half the image should be visible.
      is there any other method?

      Regards,

      Anuj
    • Hello,

      as I noticed the first approach is working for uncompressed bitmaps. If your bitmap is compressed (RLE etc) then it may end with incorrect drawing due to complex compressed data structure. Further it may concern also uncompressed bitmaps.

      Nevertheless, I'd use memory devices for that. This relieves you of image format as you copy already drawn pixel data. I simply changed the code cause I think that drawing the whole image to the half memory device may result with damaging data outside the memory device. The better way is to draw image on LCD and then copy it to memory device from LCD instead of drawing the image in memory device context:

      C Source Code: Main.c

      1. #include "DIALOG.h"
      2. // Original bitmap structure (see Image.c in attach)
      3. extern GUI_CONST_STORAGE GUI_BITMAP bmImage;
      4. // Memory device for a half bitmap
      5. GUI_MEMDEV_Handle hMem;
      6. void MainTask(void) {
      7. GUI_Init();
      8. WM_MULTIBUF_Enable(1);
      9. GUI_SetBkColor(GUI_LIGHTGRAY);
      10. GUI_Clear();
      11. // Draw original bitmap
      12. GUI_DrawBitmap(&bmImage, 50, 50);
      13. // Create memory device with a half size of the image
      14. hMem = GUI_MEMDEV_Create(50, 50, 100, 100);
      15. // Copy a half of image from LCD to memory device
      16. GUI_MEMDEV_CopyFromLCD(hMem);
      17. // Draw half bitmap from memory device
      18. GUI_MEMDEV_CopyToLCDAt(hMem, 50, 200);
      19. while (1)
      20. {
      21. GUI_Delay(50);
      22. }
      23. }
      Display All

      Alex.
    • Upd.

      If you do not want to draw the whole image on the screen before copying a half in memory device then you can use another memory device for drawing. This results in only half image displayed on the screen:

      C Source Code: Main.c

      1. #include "DIALOG.h"
      2. // Original bitmap structure (see Image.c in attach)
      3. extern GUI_CONST_STORAGE GUI_BITMAP bmImage;
      4. // Memory devices for the original and half bitmaps
      5. GUI_MEMDEV_Handle hMem, hMemHalf;
      6. void MainTask(void) {
      7. GUI_Init();
      8. WM_MULTIBUF_Enable(1);
      9. GUI_SetBkColor(GUI_LIGHTGRAY);
      10. GUI_Clear();
      11. // Create memory device for the original bitmap
      12. hMem = GUI_MEMDEV_Create(0, 0, 200, 100);
      13. // Create memory device with a half size of the image
      14. hMemHalf = GUI_MEMDEV_Create(0, 0, 100, 100);
      15. // Select "original" device
      16. GUI_MEMDEV_Select(hMem);
      17. // Draw original bitmap
      18. GUI_DrawBitmap(&bmImage, 0, 0);
      19. // Select "half" device
      20. GUI_MEMDEV_Select(hMemHalf);
      21. // Copy image from hMem to hMemHalf
      22. GUI_MEMDEV_Write(hMem);
      23. // Select LCD for drawing
      24. GUI_MEMDEV_Select(0);
      25. // Draw half bitmap from memory device
      26. GUI_MEMDEV_CopyToLCDAt(hMemHalf, 50, 50);
      27. while (1)
      28. {
      29. GUI_Delay(50);
      30. }
      31. }
      Display All

      Alex.
    • Hello,

      Thanks for the solution. The above solution works but am facing an issue with transparency of memory device.
      I have written the code as follows

      GUI_MEMDEV_Select(hMemHalf);
      GUI_SetBkColor(GUI_TRANSPARENT);
      GUI_Clear();

      This does not work. i see a black background when the memory device is written on to LCD.

      Anuj
    • Hello,

      Thanks.
      Is there any way to avoid memory devices and achieve the same result as above. As memory devices use a lot of memory i wanted to use different method.

      I plan to use image widget but as per my understanding image widget size cannot be modified at run time. Is it possible to resize image widget at run time?

      Regards,

      Anuj