There is a package react-native-image-rotate
you can rotate any image including base64
Installation
First install the package via npm
$ npm install react-native-image-rotate
then use rnpm to link native libraries
$ react-native link react-native-image-rotate
usage
static rotateImage(
uri: string,
angle: number,
success: (uri: string) => void,
failure: (error: Object) => void
) : void
Example
import React from 'react';
import { StyleSheet, View,Image, TouchableHighlight,Text } from 'react-native';
import ImageRotate from 'react-native-image-rotate';
const string = 'Your base64 image here'
export default class App extends React.Component{
constructor(props){
super(props);
this.state = {
image: string,
currentAngle: 0,
width: 150,
height: 240,
};
this.rotate = this.rotate.bind(this);
}
rotate = (angle) => {
const nextAngle = this.state.currentAngle + angle;
ImageRotate.rotateImage(
string,
nextAngle,
(uri) => {
console.log(uri, 'uri')
this.setState({
image: uri,
currentAngle: nextAngle,
width: this.state.height,
height: this.state.width,
});
},
(error) => {
console.error(error);
}
);
}
render(){
return (
<View style={{flex:1,alignItems:'center'}}>
<Image source={{uri: this.state.image}} style={{width: 300, height: 300}}/>
<TouchableHighlight
onPress={() => this.rotate(90)}
style={styles.button}
>
<Text style={styles.text}>ROTATE CW</Text>
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});