在 C 或 C 中处理图像

新手上路,请多包涵

首先,我是初学者。好的?

我已经阅读了相关的答案和问题,但请帮我解决这个问题:

如何在 C++ 中打开 JPEG 图像文件,将其转换为灰度图像,获取其直方图,将其调整为较小的图像,裁剪特定区域或显示特定区域?

对于这些任务,C 或 C++ 通常更快吗?

哪些库最简单最快?运行时间非常重要。

谢谢。

原文由 mohammad 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 612
2 个回答

这是一个使用 魔法 库的例子。

读取图像、裁剪图像并将其写入新文件的程序(异常处理是可选的,但强烈推荐):

 #include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
  // Construct the image object. Seperating image construction from the
  // the read operation ensures that a failure to read the image file
  // doesn't render the image object useless.
  Image image;

  try {
    // Read a file into image object
    image.read( "girl.jpeg" );

    // Crop the image to specified size (width, height, xOffset, yOffset)
    image.crop( Geometry(100,100, 100, 100) );

    // Write the image to a file
    image.write( "x.jpeg" );
  }
  catch( Exception &error_ )
    {
      cout << "Caught exception: " << error_.what() << endl;
      return 1;
    }
  return 0;
}

在此处查看更多示例

原文由 ayush 发布,翻译遵循 CC BY-SA 2.5 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏