0
点赞
收藏
分享

微信扫一扫

touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图


一、资源准备

准备一张图片:

touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图_touchGFX

二、touchGFX工程搭建

1、添加图片资源

touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图_控件_02

2、控件放置

注意顺序哦

touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图_学习_03


touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图_#include_04


touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图_控件_05


touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图_#include_06

touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图_学习_07


控件说明:

textArea1:滚动显示数字

imgBG:截图区域背景

image1:显示截图的内容

btnSnapshot:按下此按钮截图

3、interactions设置

touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图_touchGFX_08

三、工程源码修改

1、​​TouchGFXHAL.cpp​

添加图片缓存区

touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图_#include_09

void TouchGFXHAL::initialize()
{
// Calling parent implementation of initialize().
//
// To overwrite the generated implementation, omit call to parent function
// and implemented needed functionality here.
// Please note, HAL::initialize() must be called to initialize the framework.

TouchGFXGeneratedHAL::initialize();

#define SDRAM_START_ADDR 0xc0000000
uint32_t frame_size = DISPLAY_HEIGHT*DISPLAY_WIDTH*3;//一个帧缓冲区的大小
setFrameBufferStartAddresses((void*)SDRAM_START_ADDR, (void*)(SDRAM_START_ADDR+frame_size), (void*)(SDRAM_START_ADDR+frame_size*2));//设置三级缓存地址,最后一级是开启动画功能的
setFrameRateCompensation(true);//开启帧速率补偿,对动画有平滑的作用

//图片缓存功能
#define BITMAP_CACHE_SIZE 0x1400000 //图片缓冲区大小,这里设为20MB
Bitmap::removeCache();
Bitmap::setCache((uint16_t*)(SDRAM_START_ADDR+frame_size*3),BITMAP_CACHE_SIZE,1);//设置资源缓冲区的地址和大小,最后一个默认的0不用传,让其自动计算
Bitmap::cacheAll();//开始缓存所有的图片

}

2、​​Screen1View.hpp​

touchGFX综合学习四、touchGFX使用SnapshotWidget进行截图_#define_10

#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP

#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
#include <touchgfx/widgets/SnapshotWidget.hpp>


class Screen1View : public Screen1ViewBase
{
public:
Screen1View();
virtual ~Screen1View() {}
virtual void setupScreen();
virtual void tearDownScreen();

virtual void btn_snapshot_handler();

void handleTickEvent();
protected:

Bitmap bitmapId;

SnapshotWidget snapshotWidget;


};

#endif // SCREEN1VIEW_HPP

3、​​Screen1View.cpp​

上源码

#include <gui/screen1_screen/Screen1View.hpp>
#include <touchgfx/Unicode.hpp>

Screen1View::Screen1View():
bitmapId(BITMAP_INVALID)
{

}

void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();

snapshotWidget.setPosition(this->imgBG.getX(), this->imgBG.getY(), this->imgBG.getWidth(), this->imgBG.getHeight());
}

void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}


void Screen1View::handleTickEvent()
{
static uint16_t tickCnt = 0;
static uint16_t val = 0;

tickCnt++;
if (tickCnt >= 5)
{
tickCnt = 0;
val++;

Unicode::snprintf(this->textArea1Buffer, this->TEXTAREA1_SIZE, "%d", val);
this->textArea1.resizeToCurrentText();
this->textArea1.invalidate();
}


}



void Screen1View::btn_snapshot_handler()
{
// uint8_t *frameBuffer;
if (this->bitmapId != BITMAP_INVALID)
{
Bitmap::dynamicBitmapDelete(this->bitmapId);
this->bitmapId = BITMAP_INVALID;
}
this->bitmapId = Bitmap::dynamicBitmapCreate(this->imgBG.getWidth(), this->imgBG.getHeight(), Bitmap::RGB888);

if (this->bitmapId != BITMAP_INVALID)
{
snapshotWidget.makeSnapshot(this->bitmapId);
this->image1.setBitmap(this->bitmapId);
this->image1.invalidate();
this->box1.invalidate();

}
else
{

}
// frameBuffer = (uint8_t *)Bitmap::dynamicBitmapGetAddress(this->bitmapId);

}


举报

相关推荐

0 条评论