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();
}