我正在尝试编写以下js代码,以便在re-natal中使用react-native-camera拍照:
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={styles.preview}
type={RNCamera.Constants.Type.back}
flashMode={RNCamera.Constants.FlashMode.on}
/>
<View style={{ flex: 0, flexDirection: 'row', justifyContent: 'center' }}>
<TouchableOpacity onPress={this.takePicture.bind(this)} style={styles.capture}>
<Text style={{ fontSize: 14 }}> SNAP </Text>
</TouchableOpacity>
</View>
takePicture = async() => {
if (this.camera) {
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePictureAsync(options);
console.log(data.uri);
}
};我有下面的clojurescript代码:
(defn take-picture [camera]
(go (let [picture (<! (.takePictureAsync camera {:quality 0.5 :base-64 true}))]
(prn "uri is " (.-uri picture))
)))
(defn camera- []
(fn []
[safe-area-view
[camera {
:ref (fn [cam] (this-as this (set! (.-Camera this) cam)))
:style {:width 500 :height 500 :justify-content "flex-end" :align-items "center" :border-color "black" :min-height "10%"}
:type (-> ReactNativeCamera .-RNCamera .-Constants .-Type .-back)
}]
[view {:style {:justify-content "center"}}
[touchable-opacity {:on-press take-picture
:style {:margin 5 :background-color "#999" :padding 10 :border-radius 5}
}
[text "Take Pic"]
]]
]))但在单击触发函数take-picture的可触摸不透明度时,我得到以下错误:camera.takePictureAsync is not a function我做错了什么?
发布于 2020-03-11 15:16:11
需要确保创建了@camera-ref,然后将其传递给函数,如下例所示:
(let [camera-ref (atom nil)]
[camera {:ref #(reset! camera-ref %)}]
......
{:on-press (fn []
(let [camera @camera-ref]
(-> (.takePictureAsync camera)
(.then #(prn "image-captured: " %))
(.catch #(prn "Error capturing image: " %)))))})https://stackoverflow.com/questions/60626322
复制相似问题