I have an array of integers which represent a RGB image and would like to convert it to a byte array and save it to a file.
What\'s the best way to convert an array
I created this code and it's working pretty well:
int IntToByte(byte arrayDst[], int arrayOrg[], int maxOrg){
int i;
int idxDst;
int maxDst;
//
maxDst = maxOrg*4;
//
if (arrayDst==null)
return 0;
if (arrayOrg==null)
return 0;
if (arrayDst.length < maxDst)
return 0;
if (arrayOrg.length < maxOrg)
return 0;
//
idxDst = 0;
for (i=0; i> 8);
idxDst++;
arrayDst[idxDst] = (byte)(arrayOrg[i] >> 16);
idxDst++;
arrayDst[idxDst] = (byte)(arrayOrg[i] >> 24);
idxDst++;
}
//
return idxDst;
}
int ByteToInt(int arrayDst[], byte arrayOrg[], int maxOrg){
int i;
int v;
int idxOrg;
int maxDst;
//
maxDst = maxOrg/4;
//
if (arrayDst==null)
return 0;
if (arrayOrg==null)
return 0;
if (arrayDst.length < maxDst)
return 0;
if (arrayOrg.length < maxOrg)
return 0;
//
idxOrg = 0;
for (i=0; i