1

I've a screenshot manager that manages my screenshots for both android and iOS and it contains a function which grabs the screenshot from the list of screenshot that I have which is texture2d.

I've managed to take a screenshot for IOS but I've to convert it from UIImage to texture2d to be able to store it in the list I've created.

Am I able to convert UIImage to texture 2d? I've found some solutions but is unable to use them as I'm using Xamarin to do this and the solutions found are in Objective-C like this Convert an UIImage in a texture.

I'm not sure if I'm correct for the first 2 parts but it does not contain any errors when I tried to build it

        UIImage image = ImageToConvert;
        CGImage imageRef = image.CGImage;
        int width = (int)imageRef.Width;
        int height = (int)imageRef.Height;

        var textureData = new byte[width * height * 4];
        var colorSpace = CGColorSpace.CreateDeviceRGB ();

        int bytesPerPixel = 4;
        int bytesPerRow = bytesPerPixel * width;
        int bitsPerComponent = 8;
        var context = new CGBitmapContext (textureData, width, height,
        bitsPerComponent, bytesPerRow, colorSpace,
        CGBitmapFlags.PremultipliedLast| CGBitmapFlags.ByteOrder32Big);
        context.DrawImage(new CGRect(0, 0, width, height), imageRef);

I'm currently stuck on the third section of the conversion which is making it into a texture2d image as I'm unable to access or find opengl functions like glPixelStorei and glGenTextures.

Community
  • 1
  • 1
Mr Anoimus
  • 69
  • 11

0 Answers0