私はAndroidに取り組んでいます。そして、画像ファイルからバイト配列を取得しています。私の要件は、バイト配列ではなく、バイト型変数をサーバーに送信することです。
しかし、バイト配列を取得しているので、そのバイト配列をバイト変数に変換します。
私のコードは
InputStream in = getContentResolver().openInputStream(selectedImageUri);
byte[] imageData = readBytes(in);
byte bytedata = // here I want get the bytes from imageData array
public byte[] readBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
// and then we can return your byte array.
return byteBuffer.toByteArray();
}