[英]Append image in CIMG and save in stb_image_write not working
I am using stb_image stb_image_write and CImg with following code我正在使用带有以下代码的 stb_image stb_image_write 和 CImg
int width, height, bpp;
img = stbi_load(imgPath, &width, &height, &bpp, 3);
CImg<unsigned char> cimg(img, width, height, 1, bpp);
CImg<unsigned char> wimg(width, 10, 1, 3, 0);
cimg.append(wimg,'y');
cimg.display();
stbi_write_png("save.png", width, height, 3, cimg, width * 3);
It simply creating black line with 10 pixel and appending to bottom of image when I display this it works fine but when I save it showing distorted它只是创建 10 像素的黑线并在我显示它时附加到图像的底部它工作正常但是当我保存它时显示失真
I need to add border at bottom am I doing something wrong or any better way to do it?我需要在底部添加边框是我做错了什么还是有更好的方法?
Below code works fine read image with stb do some change in cimg and save with stb it overlay small image to big one下面的代码可以很好地使用 stb 读取图像在 cimg 中进行一些更改并使用 stb 保存它将小图像覆盖到大图像
int width, height, bpp;
int width2, height2, bpp2;
CImg<unsigned char> gradient(img1, bpp, width, height, 1);
CImg<unsigned char> overlay(img2, bpp2, width2, height2, 1);
CImg<unsigned char> gradient(img1, width, height, bpp, 1);
CImg<unsigned char> overlay(img2, width2, height2, bpp2, 1);
gradient.draw_image(0, 0, overlay);
stbi_write_png("gradient.png", width, height, 3, gradient, width * 3);
Ok I got it worked as mentioned by Mark Setchell in comments about interleave so I have to permute the buffer structure as mentioned in below post好的,我得到了 Mark Setchell 在关于交错的评论中提到的工作,所以我必须按照下面的帖子中提到的那样置换缓冲区结构
CImg library creates distorted images on rotation CImg 库在旋转时创建扭曲的图像
so if I need to used these three libs than my code would be as below所以如果我需要使用这三个库而不是我的代码如下
int width, height, bpp;
setHeader();
img = stbi_load(imgPath, &width, &height, &bpp, 3);
//Load with stb type
CImg<unsigned char> cimg(img, bpp, width, height, 1);
//Convert cimg type
cimg.permute_axes("yzcx");
//Can work with all type of cimg functions
CImg<unsigned char> wimg(width, 10, 1, 3, 0);
cimg.append(wimg,'y');
//Convert back to stb type to save
cimg.permute_axes("cxyz");
stbi_write_png("save.png", width, height+10, 3, cimg, width * 3);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.