Pangolin: 4 - Show Image 显示图像
# Object
- Show images
# Steps
## Prepare image data
```cpp
void setImageData(unsigned char * imageArray, int size){
for(int i = 0 ; i < size;i++) {
imageArray[i] = (unsigned char)(rand()/(RAND_MAX/255.0));
}
}
```
## Image texture
```cpp
const int width = 64;
const int height = 48;
pangolin::GlTexture imageTexture(width,height,GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE);
```
## Show image
```cpp
unsigned char* imageArray = new unsigned char[3*width*height];
//Set some random image data and upload to GPU
setImageData(imageArray,3*width*height);
imageTexture.Upload(imageArray,GL_RGB,GL_UNSIGNED_BYTE);
//display the image
d_image.Activate();
glColor3f(1.0,1.0,1.0);
imageTexture.RenderToViewport();
```
## Image panel
```cpp
pangolin::View& d_image = pangolin::Display("image")
//.SetBounds(2/3.0f,1.0f,0,1/3.0f,640.0/480)
.SetBounds(0.0f, 0.3f, 0.0f, pangolin::Attach::Pix(UI_WIDTH), float(w) / float(h))
.SetLock(pangolin::LockLeft, pangolin::LockTop);
std::cout << "Resize the window to experiment with SetBounds, SetLock and SetAspect." << std::endl;
std::cout << "Notice that the cubes aspect is maintained even though it covers the whole screen." << std::endl;
```
# Result
![image-20200607185606662](https://raw.githubusercontent.com/yubaoliu/assets/image/image-20200607185606662.png)
No comments