fixed so android cropping works in all orientations.
This commit is contained in:
parent
ed2768828b
commit
c51f0b5f93
|
@ -14,7 +14,6 @@ const styles = StyleSheet.create({
|
|||
},
|
||||
preview: {
|
||||
flex: 1,
|
||||
alignSelf: "stretch",
|
||||
justifyContent: 'flex-end',
|
||||
alignItems: 'center'
|
||||
},
|
||||
|
@ -187,7 +186,7 @@ export default class Example extends React.Component {
|
|||
onZoomChanged={() => {}}
|
||||
defaultTouchToFocus
|
||||
mirrorImage={false}
|
||||
cropToPreview={false}
|
||||
cropToPreview={true}
|
||||
/>
|
||||
<View style={[styles.overlay, styles.topOverlay]}>
|
||||
<TouchableOpacity
|
||||
|
|
|
@ -76,17 +76,24 @@ public class MutableImage {
|
|||
}
|
||||
}
|
||||
|
||||
public void cropToPreview(float xPercentage, float yPercentage) throws ImageMutationFailedException {
|
||||
public void cropToPreview(int orientation, float xPercentage, float yPercentage) throws ImageMutationFailedException {
|
||||
int width = this.currentRepresentation.getWidth();
|
||||
int height = this.currentRepresentation.getHeight();
|
||||
|
||||
int x = (int) Math.round(height * xPercentage);
|
||||
int y = (int) Math.round(width * yPercentage);
|
||||
|
||||
int cropWidth = width - (y*2);
|
||||
int cropHeight = height - (x*2);
|
||||
if (orientation == 1) {
|
||||
int cropWidth = width - (y*2);
|
||||
int cropHeight = height - (x*2);
|
||||
|
||||
this.currentRepresentation = Bitmap.createBitmap(this.currentRepresentation, y, x, cropWidth, cropHeight);
|
||||
this.currentRepresentation = Bitmap.createBitmap(this.currentRepresentation, y, x, cropWidth, cropHeight);
|
||||
} else {
|
||||
int cropWidth = width - (x*2);
|
||||
int cropHeight = height - (y*2);
|
||||
|
||||
this.currentRepresentation = Bitmap.createBitmap(this.currentRepresentation, x, y, cropWidth, cropHeight);
|
||||
}
|
||||
}
|
||||
|
||||
//see http://www.impulseadventure.com/photo/exif-orientation.html
|
||||
|
|
|
@ -586,8 +586,9 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
|
|||
int type = options.getInt("type");
|
||||
float paddingWidth = RCTCamera.getInstance().getPreviewPaddingWidth(type);
|
||||
float paddingHeight = RCTCamera.getInstance().getPreviewPaddingHeight(type);
|
||||
int orientation = _reactContext.getResources().getConfiguration().orientation;
|
||||
|
||||
mutableImage.cropToPreview(paddingWidth, paddingHeight);
|
||||
mutableImage.cropToPreview(orientation, paddingWidth, paddingHeight);
|
||||
} catch (MutableImage.ImageMutationFailedException e) {
|
||||
promise.reject("Error cropping image to preview", e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue