Unity3d 从“多媒体资料”中拍摄照片,并在Unity 3d中选定的圆形部分裁剪该照片?

Unity3d 从“多媒体资料”中拍摄照片,并在Unity 3d中选定的圆形部分裁剪该照片?,unity3d,Unity3d,我正在做一个项目。我想从android设备的图库中拍照。 1.如何从android设备库中拍照? 2.如何在unity3d中裁剪图片选定的圆部分?您可以使用以下代码裁剪图像。我只通过纹理2D,并根据纹理自动设置中心和半径;但是,如果需要,可以手动传递它们 Texture2D RoundCrop (Texture2D sourceTexture) { int width = sourceTexture.width; int height = sourceTextur

我正在做一个项目。我想从android设备的图库中拍照。 1.如何从android设备库中拍照?
2.如何在unity3d中裁剪图片选定的圆部分?

您可以使用以下代码裁剪图像。我只通过纹理2D,并根据纹理自动设置中心和半径;但是,如果需要,可以手动传递它们

Texture2D RoundCrop (Texture2D sourceTexture) {
        int width = sourceTexture.width;
        int height = sourceTexture.height;
        float radius = (width < height) ? (width/2f) : (height/2f);
        float centerX = width/2f;
        float centerY = height/2f;
        Vector2 centerVector = new Vector2(centerX, centerY);

        // pixels are laid out left to right, bottom to top (i.e. row after row)
        Color[] colorArray = sourceTexture.GetPixels(0, 0, width, height);
        Color[] croppedColorArray = new Color[width*height]; 

        for (int row = 0; row < height; row++) {
            for (int column = 0; column < width; column++) {
                int colorIndex = (row * width) + column;
                float pointDistance = Vector2.Distance(new Vector2(column, row), centerVector);
                if (pointDistance < radius) {
                    croppedColorArray[colorIndex] = colorArray[colorIndex];
                }
                else {
                    croppedColorArray[colorIndex] = Color.clear;
                }
            }
        }

        Texture2D croppedTexture = new Texture2D(width, height);
        croppedTexture.SetPixels(croppedColorArray);
        croppedTexture.Apply();
        return croppedTexture; 
    }
Texture2D圆形裁剪(Texture2D sourceTexture){
int-width=sourceTexture.width;
int height=sourceTexture.height;
浮动半径=(宽度<高度)?(宽度/2f):(高度/2f);
浮动中心X=宽度/2f;
浮动中心Y=高度/2f;
矢量2中心矢量=新矢量2(中心X、中心Y);
//像素从左到右、从下到上排列(即一行接一行)
Color[]colorArray=sourceTexture.GetPixels(0,0,宽度,高度);
颜色[]裁剪的颜色数组=新颜色[宽度*高度];
对于(int row=0;row
1。2.大概