-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (31 loc) · 1.5 KB
/
index.js
File metadata and controls
46 lines (31 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { NativeModules, Platform } from 'react-native';
const { RNReactNativeImageData } = NativeModules;
const ReactNativeImageData = {
getSimpleGrayscalePixels : (imagePath, {scaledWidth, scaledHeight}) => {
if (Platform.OS == "ios") {
return RNReactNativeImageData.getSimpleGrayscalePixels(imagePath, {scaledWidth, scaledHeight});
} else {
return RNReactNativeImageData.getSimpleGrayscalePixels(imagePath, scaledWidth, scaledHeight);
}
},
getSimpleGrayscalePixelsAsXYMatrix : (imagePath, {scaledWidth, scaledHeight}) => {
return new Promise((resolve, reject) => {
ReactNativeImageData.getSimpleGrayscalePixels(imagePath, {scaledWidth, scaledHeight})
.then((imagePixelsArray) => {
let imageXYMatrix = [];
for (let i = 0; i < scaledWidth; i++) {
imageXYMatrix[i] = [];
}
let index = 0;
for (let i = 0; i < scaledWidth; i++) {
for (let j = 0; j < scaledHeight; j++) {
imageXYMatrix[j][i] = imagePixelsArray[index++];
}
}
resolve(imageXYMatrix);
})
.catch(() => {reject()});
})
}
}
export default ReactNativeImageData;