vs2017调试内存中的图片数据

vs2017下载安装插件 ImageWatch2017

在这里插入图片描述
//在需要调试图片的地方加入读取图片像素地址和大小的代码,这个例子中只需要:
像素数据地址:buff
图片实际宽度:_width
图片实际高度:_height
然后在获取到这三个要素的后面打个断点

if (DRAW_UNIT_DEBUG)
{
	SnPicture* pic = SnPicture::NEW();
	pTempD1->GetCanvas()->captureColorPicture(*pic);
	uint32_t* buff = (uint32_t*)pic->getPixelData().getData();
	int _width = pTempD1->GetInnerRect().m_width;
	int _height = pTempD1->GetInnerRect().m_height;
	if (false) {  //上下颠倒
		uint32_t* row = (uint32_t*)malloc(sizeof(uint32_t)*_width);
		for (int i = 0; i < _height/2; i++) {
			uint32_t* buff1 = buff + i  *  _width;
			uint32_t* buff2 = buff + (_height - i - 1) *  _width;
			std::copy(buff2, buff2 +_width, row);
			std::copy(buff1, buff1 + _width, buff2);
			std::copy(row, row + _width, buff1);
		}
		free(row);
	}
	if (true) {//ABGR to ARGB,方便mfc调试
		for (int i = 0; i < _width*_height; i++) {
			uint32_t color = buff[i];
			buff[i] = (color & 0xFF000000) | (((color >> 16) & 0xFF)) | (((color >> 8) & 0xFF) << 8) | ((color & 0xFF) << 16);
		}
	}
	char pngPath[50];
	sprintf(pngPath, "/sdcard/Download/pTempD1_%d.png", ii++);
	pic->save(pngPath, "png");
	pic->release();
}

打开vs2017 视图->其他窗口->Image Watch
设置:@mem(buff,UINT8, 4, _width,_height, _width*4)
在这里插入图片描述
执行到断点处即可看到图片内容:
ABGR显示
在这里插入图片描述ABGR转为ARGB:
在这里插入图片描述封装


class DrawUnitDebug {
public:
	DrawUnitDebug(DrawModule::DrawBase::DrawUnit * du, uint32_t* &buff, int& _width, int& _height,bool to_argb=true,bool flip=false) {
		getBuf(du, buff, _width, _height);
		if (flip)
			flipBuf();
		if (to_argb)
			toARGB();
	}
	void getBuf(DrawModule::DrawBase::DrawUnit * du, uint32_t* &buff, int& w, int& h) {
		m_pic = DrawModule::SnPicture::NEW();
		du->GetCanvas()->captureColorPicture(*m_pic);
		m_buff = (uint32_t*)m_pic->getPixelData().getData();
		m_width = du->GetInnerRect().m_width;
		m_height = du->GetInnerRect().m_height;
		buff = m_buff;
		w = m_width;
		h = m_height;
	}
	void flipBuf() {//上下颠倒图片
		uint32_t* row = (uint32_t*)malloc(sizeof(uint32_t)*m_width);
		for (int i = 0; i < m_height / 2; i++) {
			uint32_t* buff1 = m_buff + i * m_width;
			uint32_t* buff2 = m_buff + (m_height - i - 1) *  m_width;
			std::copy(buff2, buff2 + m_width, row);
			std::copy(buff1, buff1 + m_width, buff2);
			std::copy(row, row + m_width, buff1);
		}
		free(row);
	}
	void toARGB() {//ABGR to ARGB,方便mfc调试
		for (int i = 0; i < m_width*m_height; i++) {
			uint32_t color = m_buff[i];
			m_buff[i] = (color & 0xFF000000) | (((color >> 16) & 0xFF)) | (((color >> 8) & 0xFF) << 8) | ((color & 0xFF) << 16);
		}
	}
	void save(char* path) {
		m_pic->save(path, "png");
	}
	void release() {
		m_pic->release();
	}
private:
	uint32_t* m_buff=nullptr;
	int m_width = 0;
	int m_height = 0;
	DrawModule::SnPicture* m_pic = nullptr;
};

使用

if (DRAW_UNIT_DEBUG)
{
	uint32_t* buff=nullptr;
	int _width ,_height ;
	DrawUnitDebug *duDebug =new DrawUnitDebug(pTempD1, buff, _width, _height);
	char pngPath[50];
	sprintf(pngPath, "/sdcard/Download/pTempD1_test.png");
	duDebug->save(pngPath);
	duDebug->release();
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值