React native 反应本机视图快照曲面gl反应本机

React native 反应本机视图快照曲面gl反应本机,react-native,opengl,React Native,Opengl,请注意,我正在尝试快照动态添加的曲面和文本的viewshot视图,但在导出图像时无法看到文本 <Viewshot> <Surface style={{ width:Dimensions.get('screen').width, height:Dimensions.get('screen').height, zIndex: 0 }} ref={(el) => this.surface = el}> <Hudson><GLIma

请注意,我正在尝试快照动态添加的曲面和文本的viewshot视图,但在导出图像时无法看到文本

<Viewshot>
    <Surface style={{ width:Dimensions.get('screen').width, height:Dimensions.get('screen').height, zIndex: 0 }} ref={(el) => this.surface = el}>
        <Hudson><GLImage source={{ uri: this.state.preview.uri }} resizeMode={'cover'}></Hudson>
    </Surface>
        <Draggable style={{}} x={0} z={0} minX={0} maxX={Dimensions.get('window').width} y={Dimensions.get('window').height / 3}>
            <PinchGestureHandler {...gesture}>
                <Animated.View style={[{ width: Dimensions.get('window').width, height: 'auto', backgroundColor: 'rgba(0, 0, 0, 0.1)', paddingHorizontal: 20, textAlign: 'center', paddingVertical: 10, saving: false }, { transform: [{ scale }] }]}>
                    <Text style={{ color: '#FFF', fontFamily: 'Nunito-Bold', fontSize: 16 }}>{text}</Text>
                </Animated.View>
            </PinchGestureHandler>
        </Draggable>
</ViewShot>

this.surface=el}>
{text}

回答这类问题时更容易获得更多信息,如:

  • 本机视图快照的版本
  • 您为之开发的平台
我假设你是为android开发的

从3.0.2开始的react本机视图快照不支持android上的gl react。您可以在源主页上查看互操作性表:

但是,您可能希望尝试使用。它可能会做你需要它做的事情。或者,您也可以修改其中一个包的源代码,以正确地截图一张图片。我不确定这是否能解决您的问题,但前几天我在查找类似问题的解决方案时发现:

//源代码取自:https://stackoverflow.com/questions/4731589/android-opengl-screenshot
公共静态位图保存像素(整数x、整数y、整数w、整数h、GL10 gl)
{  
int b[]=新int[w*(y+h)];
int bt[]=新的int[w*h];
IntBuffer ib=IntBuffer.wrap(b);
ib.位置(0);
gl.glReadPixels(x,0,w,y+h,GL10.gl_RGBA,GL10.gl_无符号字节,ib);
对于(inti=0,k=0;i16)&0xff;

int pr=(非常感谢你,是的,我是为android开发的,我使用的是react native 0.62
// source taken from: https://stackoverflow.com/questions/4731589/android-opengl-screenshot
public static Bitmap SavePixels(int x, int y, int w, int h, GL10 gl)
{  
     int b[]=new int[w*(y+h)];
     int bt[]=new int[w*h];
     IntBuffer ib=IntBuffer.wrap(b);
     ib.position(0);
     gl.glReadPixels(x, 0, w, y+h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib);

     for(int i=0, k=0; i<h; i++, k++)
     {//remember, that OpenGL bitmap is incompatible with Android bitmap
      //and so, some correction need.        
          for(int j=0; j<w; j++)
          {
               int pix=b[i*w+j];
               int pb=(pix>>16)&0xff;
               int pr=(pix<<16)&0x00ff0000;
               int pix1=(pix&0xff00ff00) | pr | pb;
               bt[(h-k-1)*w+j]=pix1;
          }
     }


     Bitmap sb=Bitmap.createBitmap(bt, w, h, Bitmap.Config.ARGB_8888);
     return sb;
}