在c++中通过坐标获取png
Getting png by the coordinates in C++
我想知道是否有任何c++或C的库,允许通过坐标获得png-image。例如:我已经打开了png文件,我只需要得到从
开始的部分。x = 5
y = 5
w = 10
h = 10
and so on
那么哪个库允许这样的操作呢?Thanks on advance
Using 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" );
}
大多数库都会为您做这些。OpenCV:
标题:
#include <cv.h>
#include <highgui.h>
代码:IplImage *im = cvLoadImage("input.png");
cvSetImageROI(im, cvRect(x, y, w, h));
cvShowImage("output.png", im);
就像@misha说的,大多数库都有这个功能。的提振。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
相关文章:
- 如何在C++中获取坐标?
- 使用 GTK3 C++获取指针坐标
- 从 CGAL 3D 网格生成中获取顶点坐标的 -6.27744e+66:mesh_implicit_sphere示例
- 如何从 3d 对象文件中获取 3d 坐标
- 从 3 个视点在 3 张图像上有 3 个点如何在 3D 空间中获取其坐标?
- 如何从 DirectXTK (ToolKit) DirectX::Model 类获取所有顶点坐标以用于冲突检测
- 获取具有X,Y和距离的OPENCV中的3D坐标
- 获取QImage像素坐标
- OpenCV从2D像素获取3D坐标
- 如何通过调用 gluUnproject 两次(不使用 gluUnProject)从场景坐标中获取深度值
- 获取数独块的坐标
- 在调整大小窗口时,如何使用鼠标单击来获取图像的坐标
- 将圆圈分为n相等的部分,以获取每个分界点的坐标
- 从卫星的ECI坐标获取地球上的纬度和经度点
- Android NDK-如何从TAP中获取坐标并将其显示在文本视图上
- OpenGL获取离当前鼠标位置最近的世界三维点的三维坐标
- 当用户按 Ctrl 并单击时获取鼠标坐标
- 获取RGBDemo的鼠标位置坐标
- D3D:如何从 x,y 坐标获取颜色
- 在c++中通过坐标获取png