gpt4 book ai didi

c++ - 放大图像

转载 作者:行者123 更新时间:2023-11-28 08:29:51 24 4
gpt4 key购买 nike

这不是段错误,但它不是读取“原始”文件的像素。

Image Image::scaleUp(int numTimes) const
{
Image newImage(width*numTimes, height*numTimes);
newImage.createImage(width*numTimes, height*numTimes);

for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
for(int inner_x = 0; inner_x < numTimes; inner_x++){
for (int inner_y = 0; inner_y < numTimes; inner_y++){
newImage.pixelData[x*numTimes+inner_x][y*numTimes+inner_y] = pixelData[x][y];
}
}
}
}
return newImage;
}

现在解决了*(*除了我的图片是黑白的)

最佳答案

您的代码似乎使颜色更亮(将它们乘以 numTimes)。这是你想做的吗?

如果你想返回图像的拷贝,你应该在应用你的转换之前制作一个拷贝,然后返回对该图像的引用。也许您的 Image 类已经有一个复制构造函数,您可以使用它来获取拷贝(如果没有,您将不得不添加它或使用另一种构造对象的方法)。

我想这就是你想要的:

Image Image::scaleUp(int numTimes) const
{
Image newImage = new Image(); // You might have a constructor to specify size so data is pre-allocated ?

// Your copy-and-scale code, but set data in newImage ....
// Using copyAll here should be avoided, since it is just copying data
// that you will need to set again when doing the scaling.

return newImage;
}

关于c++ - 放大图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2648908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com