-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image (screenshot) with lookup filter not able to convert to Data #14
Comments
The entire Data object I get back for this screenshot is:
You can copy and paste this into a tool like https://onlinejpgtools.com/convert-data-uri-to-jpg to see the output - completely white. I first thought it might be due to my lookup filters, but then again, it shows correctly in the UIImageView (the preview) so I want to get that image into the Data object as well. |
Sorry, I can not reproduce the problem. I have tried to convert screenshot (and other PNG) image to data, and convert data back to image to display it. It works fine. Does your server change the uploaded data? One more tip: PNG contains alpha channel, but JPEG dose not. If you convert a transparent PNG to JPEG, you will lose the alpha channel, and the image will be opaque. |
I have used this library to add filters to images or videos my users record within my app. Additionally, they can choose images from their gallery to import those and add the same filters.
I create my filters using a lookup table in Photoshop and adding additional filters, changing only colors and not blurring or sharpening, so the lookup files are OK.
It all works fine with real images, but as soon as I import a screenshot, it seems to mess up the conversion to a Data object. It looks good in the UIImage itself, but to upload it to my server, I need the Data of this image.
This is what my app looks like when opening a screenshot (crop and resize automatically).
This is what the preview (UIImageView) looks like with a black and white filter enabled - this is good.
However, this is what the result looks like in a new UIImage (converted from Data) - the left two images are blank, completely white, while I want it to show the black and white image (as a thumbnail).
I append the filters in an array in the most simple way possible, like this:
self.filteredImages.append(BBMetalLookupFilter(lookupTable: UIImage(named: "lookup_01")!.bb_metalTexture!).filteredImage(with: extractedImage!)!)
Also tried the complexer and async methods, but the result is the same. Then, to convert it to Data, I do this:
I retrieve the data in another view controller:
This works perfectly fine with regular images from the gallery, video from gallery (I take a snapshot of the first frame of the video), images taken within the app and video taken within the app. The problem seems to occur only when it involves a screenshot in the gallery. I noticed a screenshot is a PNG file rather than a JPEG file, so I tried encoding it as pngData() instead of jpegData(compressionQuality: 1), but this doesn't change anything either.
Any idea on how this can be resolved? The main idea is of course to let users use "real" photos, but if they choose a screenshot for any reason whatsoever, I would like it to work as well.
The text was updated successfully, but these errors were encountered: