//but first : check !
if (mat.depth() == CvType.CV_8U) { //bytes !
byte[] buffer = new byte[mat.total() * mat.channels()];
mat.get(0,0,buffer);
} else
if (mat.depth() == CvType.CV_32F) { //float !
float[] buffer = new float[mat.total() * mat.channels()];
... etc