Javascript 在Android上使用Unity ExternalTexture
我尝试使用外部纹理从Android智能手机带来带有Unity3D和JavaScript的PNG文件 SetupExternalTexture与下面相同,我得到了nativeTextureIDJavascript 在Android上使用Unity ExternalTexture,javascript,c#,android,unity5,Javascript,C#,Android,Unity5,我尝试使用外部纹理从Android智能手机带来带有Unity3D和JavaScript的PNG文件 SetupExternalTexture与下面相同,我得到了nativeTextureID nativeTextureID = _activity.Call<System.Int32>("SetupExternalTexture"); public int SetupExternalTexture() { int textureid[] = new int[1]; GLES2
nativeTextureID = _activity.Call<System.Int32>("SetupExternalTexture");
public int SetupExternalTexture() {
int textureid[] = new int[1];
GLES20.glGenTextures(1, textureid, 0);
UnityTextureNativeID = textureid[0];
//String pictureDirectory = Environment.getExternalStorageDirectory() + "/Download/sa.jpg";
String pictureDirectory = Environment.getExternalStorageDirectory() + "/Pictures/untitled.png";
//Bitmap bitmap = BitmapFactory.decodeFile("/storage/emulated/0/Pictures/untitled.png");
Bitmap bitmap = BitmapFactory.decodeFile(pictureDirectory);
ByteBuffer byteBuffer = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsFromBuffer(byteBuffer);
prevWidth = bitmap.getWidth();
prevHeight = bitmap.getHeight();
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, UnityTextureNativeID);
GLUtils.texImage2D(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0, bitmap, 0);
//GLES20.glTexImage2D(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0, GLES20.GL_RGBA, prevWidth, prevHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, byteBuffer);
GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
return UnityTextureNativeID;
}
但是,我有一个奇怪的图像。。。有人帮我吗
//怪象
//想要形象
您不能添加您希望看到的内容吗?正常图片(.png文件)是的,但是png文件看起来像什么?这可能有助于了解颜色字节是否在移动等。我编辑!上传我想要的照片
Unity texture = Texture2D.CreateExternalTexture(texWidth, texHeight, TextureFormat.ARGB32, false, false, new System.IntPtr(nativeTextureID));