[magick-users] Joining 2 image halves (C++ api)

bill_barrington at bellsouth.net bill_barrington at bellsouth.net
Wed Oct 17 12:12:25 PDT 2007


Hello,

What I would like to do is very simple. Basically, I would like to use the C++ API to perform the same thing that the following 'convert' command line tool does:
convert +append lhs rhs joined

The C++ code follows. It's being called using JNI, hence the jints, etc.  Can someone steer me to the solution?  Thanks.


jint joinImageHalves(jbyte *lhs, jint lhsLen, jbyte *rhs, jint rhsLen, jbyte* &image) {
  cerr << "Creating lhs" << endl;
  Blob lhsBlob((unsigned char*)(lhs), lhsLen);
  Image lhsImage(lhsBlob);

  cerr << "Creating rhs" << endl;
  Blob rhsBlob((unsigned char*)(rhs), rhsLen);
  Image rhsImage(rhsBlob);
  
  Geometry lhsGeom = lhsImage.size();
  Geometry rhsGeom = rhsImage.size();
  if(lhsGeom.width() != rhsGeom.width() || lhsGeom.height() != rhsGeom.height()) 
  	throw invalid_argument("Geometry of image halves differs"); 	
  int w = lhsGeom.width();
  int h = lhsGeom.height();

  Image joined(Geometry(w*2, h), Color("white"));  // Canvas
  cerr << "Created canvas" << endl;
  joined.composite(lhsImage, 0, 0);
  joined.composite(rhsImage, w, 0);
 
  cerr << "Writing to blob" << endl;
  Blob imageBlob;

  // BLOWS UP HERE DURING THE WRITE TO THE BLOB
  joined.write(&imageBlob);
  // ...


More information about the Magick-users mailing list