Navigation

    全志在线开发者论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • 在线文档
    • 社区主页

    【FAQ】全志R329 MiniGUI如何获取和设置BITMAP像素点?

    其它全志芯片讨论区
    r329 r818 faq 技术支持
    1
    1
    157
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • q1215200171
      budbool LV 8 last edited by

      问题描述

      在MiniGUI中使用FillBoxWithBitmap加载一张图片后,需要获取到每一个像素点并重新设置像素点,实时更新内存中图像数据,做一些特效,比如旋转

      问题分析

      通过FillBoxWithBitmap加载图片后,返回的是BITMAP结构体,里面包含指向图像内存的指针bmBits,因此访问和修改该指针里的内容即可修改

      解决方案

      需要一个结构体来存RGBA数据

      typedef struct tagRGBQUAD {
          BYTE rgbBlue;
          BYTE rgbGreen;
          BYTE rgbRed;
          BYTE rgbReserved;
      } RGBQUAD;
      

      下面是获取像素的方法

      static void getPixel(PBITMAP src) {
          RGBQUAD srcdib[src->bmWidth * src->bmHeight];
          int x, y, point = 0;
          Uint8 *srcrow;
          Uint32 pixel;
      
          /* 循环获取像素点 */
          for (y = 0; y < src->bmHeight; y++) {
              for (x = 0; x < src->bmWidth; x++) {
                  /* 得到像素点的地址 */
                  srcrow = (Uint8 *) src->bmBits + y * src->bmPitch
                          + x * src->bmBytesPerPixel;
                  pixel = *((Uint32 *) (srcrow));
                  /* 这是MiniGUI中根据Pixel转成RGBA的函数 */
                  Pixel2RGBA(HDC_SCREEN, pixel, &srcdib[point].rgbRed,
                          &srcdib[point].rgbGreen, &srcdib[point].rgbBlue,
                          &srcdib[point].rgbReserved);
                  /* 打印看看对不对 */
                  printf("%d %d %d %d\n", srcdib[point].rgbReserved,
                          srcdib[point].rgbRed, srcdib[point].rgbGreen,
                          srcdib[point].rgbBlue);
                  /* 记录点的位置 */
                  point++;
              }
          }
      }
      

      下面是设置像素的方法

      static void setPixel(PBITMAP src, PBITMAP dstbmp) {
          /* 这里根据源图片重新构造一个PBITMAP对象 */
          dstbmp->bmType = src->bmType;
          dstbmp->bmBitsPerPixel = src->bmBitsPerPixel;
          dstbmp->bmBytesPerPixel = src->bmBytesPerPixel;
          dstbmp->bmAlpha = src->bmAlpha;
          dstbmp->bmColorKey = src->bmColorKey;
      #ifdef _FOR_MONOBITMAP
          dstbmp->bmColorRep = src->bmColorRep;
      #endif
          dstbmp->bmAlphaMask = src->bmAlphaMask;
          dstbmp->bmAlphaPitch = src->bmAlphaPitch;
          dstbmp->bmWidth = src->bmWidth;
          dstbmp->bmHeight = src->bmHeight;
          dstbmp->bmPitch = src->bmPitch;
          dstbmp->bmBits = malloc(src->bmWidth * src->bmHeight * src->bmBytesPerPixel);
      
          /* dstdib存的是自己需要的每个像素点的值,根据需要自己赋值 */
          RGBQUAD dstdib[src->bmWidth * src->bmHeight];
          int x, y, point = 0;
          Uint32 pixel;
          
          /* 设置每一个像素点的值 */
          for (y = 0; y < src->bmHeight; y++) {
              for (x = 0; x < src->bmWidth; x++) {
                  pixel = RGBA2Pixel(HDC_SCREEN, dstdib[point].rgbRed,
                          dstdib[point].rgbGreen, dstdib[point].rgbBlue,
                          dstdib[point].rgbReserved);
                  /* 打印看看像素是否正常 */
                  printf("%d %d %d %d\n", dstdib[point].rgbReserved,
                   dstdib[point].rgbRed, dstdib[point].rgbGreen,
                   dstdib[point].rgbBlue);
                  printf("pixel=%x\n", pixel);
      
                  /* MiniGUI根据pixel设置像素点的函数 */
                  SetPixelInBitmap(dstbmp, x, y, pixel);
                  /* 记录点的位置 */
                  point++;
              }
          }
      }
      
      1 Reply Last reply Reply Quote Share 0
      • Referenced by  q1215200171 q1215200171 
      • Referenced by  q1215200171 q1215200171 
      • Referenced by  q1215200171 q1215200171 
      • Referenced by  q1215200171 q1215200171 
      • Referenced by  q1215200171 q1215200171 
      • 1 / 1
      • First post
        Last post

      Copyright © 2022 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

      行为准则 | 用户协议 | 隐私权政策