RoboVM中的图像

时间:2015-08-25 11:57:31

标签: ios robovm

我使用robovm并希望显示我在UIImage中远程接收的一些图像。有两种方法可以获取图像(由于它们来自其他来源,因此无法更改)。一些以JPEG格式发送,一些以int数组中的像素形式发送。现在,转换为UIImage的int图像拒绝像这里一样绘制到图像上下文中,

    NSData imgData = new NSData(array);
    CGDataProvider provider = CGDataProvider.create(imgData);
    CGImage img = CGImage.create((long) size.getWidth(), (long) size.getHeight(),
                8, 32, (long) (size.getWidth()) * 4, CGColorSpace.createDeviceRGB(), new CGBitmapInfo(CGImageAlphaInfo.PremultipliedFirst.value()),
                provider, null, false, CGColorRenderingIntent.Default);
    UIGraphics.beginImageContext(size);
    fullscreen.draw(CGPoint.Zero(), CGBlendMode.Normal, 1.0);
    UIImage uimg = new UIImage(img);
    uimg.draw(new CGRect(rect.x, rect.y, rect.width, rect.height), CGBlendMode.Normal, 1.0);
    fullscreen = UIGraphics.getImageFromCurrentImageContext();
    UIGraphics.endImageContext();

但是当这样做时它会正确显示:

    NSData imgData = new NSData(array);
    CGDataProvider provider = CGDataProvider.create(imgData);
    CGImage img = CGImage.create((long) size.getWidth(), (long) size.getHeight(),
                8, 32, (long) (size.getWidth()) * 4, CGColorSpace.createDeviceRGB(), new CGBitmapInfo(CGImageAlphaInfo.PremultipliedFirst.value()),
                provider, null, false, CGColorRenderingIntent.Default);
    fullscreen = new UIImage(img);

然而,在这种情况下,我无法在JPEG旁边显示图像,因为它需要首先绘制背景。我该怎么办?

1 个答案:

答案 0 :(得分:0)

int数组需要在转换为CGImage之前通过此循环:

    for(int i=0; i<data.length; i++) {
        data[i] = pixels[i] | 0xff000000;
    }

因为默认情况下,alpha(顶部字节)为零,图像不可见。