I am new to react native and I am practicing converting images into binary files. I randomly downloaded the image from the internet. I am trying to convert images into binary files to upload to the server through API. The server takes input as a binary file. I have attached the code below. I searched on the internet but could not find the solution.
import React from 'react'
import {
View,
Text,
StyleSheet,
Image,
Button,
Alert
} from 'react-native'
let imagePath = './src/image/macTest.jpeg'
const imageToBinary = (imagePath) => {
//Alert.alert(imagePath)
// this function needs to convert image into the binary file
}
const App = () => {
return (
<View>
<Text style={styles.headerStyle}> Image </Text>
<Image
style={styles.imageStyle}
source= {require('./src/image/macTest.jpeg')}
/>
<Button
title="Binary Value"
onPress={() => imageToBinary(imagePath)}
/>
<View style= {styles.binaryStyle}>
<Text>
// binary value of the image
</Text>
</View>
</View>
)
}
const styles = StyleSheet.create({
headerStyle:{
fontSize: 20,
textAlign: 'center',
margin: 15
},
imageStyle:{
alignItems: 'center',
height: 300,
width: 450,
},
binaryStyle: {
borderWidth: 1,
borderColor: 'black',
width: 400,
height: 250,
margin: 5
}
})
export default App;