c++ - magick++:cut out a image to a new image -


i want cut out image , save in new image. new image written file right, printed pixels wrong. why?

magick::image cutout(magick::image & image, point const & pos,     size_t width, size_t height) {     size_t const buffersize = width*height*3*sizeof(char);     std::unique_ptr<char[]> buffer(new char[buffersize]);     image.write(pos.x, pos.y, width, height, "rgb",             magick::charpixel, buffer.get());     magick::image res(width, height, "rgb",             magick::charpixel, buffer.get());     return res; }  magick::image cutoutdigit(magick::image & image,         fixestype const & fixes, point const & pos) {     point lt = transform(fixes, pos);     point rb = transform(fixes,             point(pos.x+digitwidth, pos.y+digitheight));     auto newimage = cutout(image, lt, rb.x-lt.x, rb.y-lt.y);     magick::geometry g(digitwidth,digitheight);     g.aspect(true);     newimage.resize(g);     return newimage; }  void print(magick::pixelpacket * pixels, size_t columns, size_t rows) {     ( size_t = 0; < rows; ++i) {         ( size_t j = 0; j < columns; ++j) {             if (pixels->red < 0x80) {                 std::cout << '#';                 } else {                 std::cout << ' ';             }             //std::cout << std::hex << std::setfill('0') << std::setw(2) << (pixels-    >green & 0xff);             ++pixels;         }         std::cout << std::endl;      } }  char recognition(magick::image & image) {     magick::pixels view(image);     magick::pixelpacket * pixels = view.get(0,0,digitwidth,digitheight);      print(pixels,image.columns(),image.rows());      return judge(is_connected(pixels, 2, {0,3,4})         | is_connected(pixels, 1, {0,3})         | is_connected(pixels, 5, {3,4})); }  int main() {     ...     auto i(cutoutdigit(image,fixes,point(130+c*126, 130+r*156)));     std::cout << recognition(i) << ' ';     i.write("new。gif");     ... } 

are there other solutions can cutout image , image won't change?


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -