I tried to load the image from the link with UnityWebRequestTexture.GetContent() then got the message “Data Processing Error, see Download Handler”,
after that I checked uwr.DownloadHandler.error I got the error “Failed to create texture from downloaded bytes”… does anyone know why?
After some testing, there seems to be something with the image data itself.
If I put it into paint and re-save it as a jpg, it loads just fine.
So something has been done to this image’s data that Unity cannot process.
You could send a bug report with the image.
But it may just be easier to re-save the image and then upload it again.
Used code:
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class TextureDownloader : MonoBehaviour
{
public string Url;
public RawImage Image;
private IEnumerator Start()
{
using var textureRequest = UnityWebRequestTexture.GetTexture(Url, false);
yield return textureRequest.SendWebRequest();
if (textureRequest.result != UnityWebRequest.Result.Success)
{
Debug.Log(textureRequest.downloadHandler.data.Length);
Debug.LogError($"Download was not a success. {textureRequest.result}\nError: {textureRequest.error}\nDownloadHandlerError: {textureRequest.downloadHandler.error}", this);
yield break;
}
Image.texture = DownloadHandlerTexture.GetContent(textureRequest);
}
}
@esanuriana08 , we have exactly the problem in our App. A user uploads an image to our backend and the App requests the image URL so we can download it on the device and display it.
The problem is that the Api UnityWebRequestTexture.GetTexture() cannot convert the downloaded image bytes using Color space: CMYK into texture at runtime. See the attached image:
Well. CMYK is usually only used in the printing industry. Not sure why anyone would use such an image to be passed around the internet. If it’s a corporate logo or image that was produced by some artists, the image provided probably was meant for printing.
The JPEG standard could support all sorts of formats and color spaces. However almost nobody supports the whole standard. In most cases we actually talk about the JFIF standard with is a lot simpler but still allows many variants which are not necessarily supported by every jpeg framework. So you either want to store the image in a more common format or if you need to support exotic variants, you probably want to include a third party image loader that supports the format you’re after.
Yep, I know it. But you know users, they/we always do random crazy stuff and when working on Photoshop it could be that someone by mistake would save it as CMYK format and upload the image, even when they are told that is not allowed.
The way to go in our case is to add a validation to the web form to display a message to the user when they try to upload the image using CMYK format.
I got the same error message with someone’s PNG file.
It is not a really helpful conclusion to just say “it’s the image’s problem” if every other program in existence (Paint, Photos, Gimp, every browser etc) can load it just fine. There must be a reason Unity couldn’t read it but other programs can. It would be a bug in Unity.
Yes if we resave the image it will load correctly, but that requires calling an imagemagick script and running it on everything output by the user’s image generation program. Which is hardly a desirable workaround when you consider that only a very small percentage of users would be having this issue, and 99% of people using their image generation program are producing images that Unity can read without this gimmicky workaround.
I guess as a compromise I could call imagemagick only if it doesn’t load at first. That way only the users producing the problematic images would suffer the small performance hit
No, this is the wrong approach. Many programs try to figure out which format a certain file has, regardless of the extension, other progams rely on the extension. If the extension is wrong, it simply can not load the file. If the file contains a jpeg/JFIF file but has the extension “png”, it’s just wrong. It’s irrelevant if other pieces of software can load the image. I recently came across many jpg files which were actually webp images but they had the extension “jpg”. Most programs could load and display the file, however windows own image viewer would actually softlock on such images. It does load and display the image, but it suddenly refused to jump to the next image. When I renamed the image to the proper “webp” extension, everything worked correctly.
Apart from that the jpeg standard is huge. Almost no loader on this planet actually supports all possible variants. Most even only support the stripped down JFIF standard. But even this standard has so many rare special cases that you rarely find a loader that can handle all of them. Yes, you could say that it’s an issue with the loader. However if it’s a really rare format variant, it’s also an issue with the image.
If you have an issue with a particular image, share it, if possible and we can have a look. Though, don’t embed it here as I’m not sure if the image will be converted. We need to get hold of the raw file in order to have a look at the file. As I said in many cases the files have the wrong extension, so looking at the file content would help to clear that up.
You are probably right. My game was saving the json responses as pngs, so I’ll take a closer look. There is still a mystery of why it’s only for that user and also used to work fine, but maybe it’s at least a confounding factor. Thanks for the tip!