在C图像工作++或C [英] Working with images in C++ or C

查看:100
本文介绍了在C图像工作++或C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的第一件事就是,我是一个初学者。好吗?

The first thing is that I am a beginner. Okay?

我读过相关答案和问题,但请大家帮我解决这个问题:

I've read related answers and questions, but please help me with this problem:

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

How can I open an JPEG image file in C++, convert it to a grayscale image, get its histogram, resize it to a smaller image, crop a particular area of it, or show a particular area of it?

有关这些任务,是C或C ++一般的快?

For these tasks, is C or C++ faster in general?

什么库是简单和最快?运行时间是非常重要的。

What libraries are simplest and fastest? The running time is very important.

感谢。

推荐答案

下面是使用难懂库为例

方案,其中读取图像,作物它,并将其写入到一个新的文件(异常处理是可选的,但强烈推荐):

program which reads an image, crops it, and writes it to a new file (the exception handling is optional but strongly recommended):

#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;
}

这里查看更多的例子。

这篇关于在C图像工作++或C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆