【问题标题】:Getting png by the coordinates in C++在 C++ 中通过坐标获取 png
【发布时间】:2011-12-01 14:26:39
【问题描述】:

我想知道是否有任何 C++ 或 C 库允许通过坐标获取 png-image。例如: 我打开了 png 文件,我只需要获取它的 parf,它从

开始
x = 5
y = 5
w = 10
h = 10
and so on

那么什么库允许做这样的操作呢? 提前感谢

【问题讨论】:

    标签: c++ c png


    【解决方案1】:

    使用Magic++

    #include <Magick++.h> 
    using namespace Magick; 
    
    void main()
    {
        Image image;
        image.read( "in.png" );
    
        // Crop the image to specified size (width, height, xOffset, yOffset)
        image.crop( Geometry(10, 10, 5, 5) );
    
        // Write the image to a file
        image.write( "out.png" ); 
    }
    

    【讨论】:

      【解决方案2】:

      大多数图书馆都会为您做到这一点。在 OpenCV 中:

      标题:

      #include <cv.h>
      #include <highgui.h>
      

      代码:

      IplImage *im = cvLoadImage("input.png");
      cvSetImageROI(im, cvRect(x, y, w, h));
      cvShowImage("output.png", im);
      

      【讨论】:

      • 是否可以使用openGL来做到这一点?
      • AFAIK OpenGL 根本无法加载/保存图像。 OpenGL 与任何图像 I/O 无关,因此不能用于此类任务。
      【解决方案3】:

      就像@misha 所说,大多数库都有这个功能。 boost.GIL 库也可以做到:

      #include <boost/gil/gil_all.hpp>
      // I need this bugfix to compile against libpng 1.5, your mileage may vary
      #define int_p_NULL (int*)NULL
      // done with the fix
      #include <boost/gil/extension/io/png_dynamic_io.hpp>
      int main()
      {
          boost::gil::rgb8_image_t img;
          png_read_image("in.png", img);
          png_write_view("out.png", subimage_view(const_view(img), 5, 5, 10, 10));
      }
      

      编译时只需要-lpng

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-08
        • 1970-01-01
        • 2019-10-11
        • 1970-01-01
        • 1970-01-01
        • 2011-08-06
        相关资源
        最近更新 更多