UIImagePickerControllerEditedImage edited image offset for iOS 11 - uiimageview

I'm using a UIImagePickerController with allowsEditing enabled to share images in an App, but found that cropped image is offset for devices running iOS 11 only.
My UIImagePickerControllerDelegate implementation is quite simple, just standard actions:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image = info[UIImagePickerControllerEditedImage] as! UIImage
imageView.image = image
picker.dismiss(animated: true, completion: nil)
}
Below you can see difference. iOS 10 on the right, iOS 11 on the left. You can see the iOS 11 image is offset down, even though the cropping rectangle was put in exactly the same place.
Here is a video demonstrating the issue: https://www.dropbox.com/s/4csofidjcrc9ah6/UIImagePickerControllerEditedImageOffset.mp4?dl=0
I also created a demo project on GitHub to demonstrate the issue: https://github.com/aivars/photo-Picker-Tests
I would guess that it is UIImagePickerController bug, but wonder why do not find any other error reports online.
I also filed a bug report with Apple: http://www.openradar.me/36292067

Related

Anchor detection issues in AR application

I have an augmented reality app with a simple Reality Composer project.
It works fine on an ipad 14.4 but I'm having problems on higher versions (14.7 and 15).
Anchor detection is much more sensitive. This has the consequence of restarting my scenes with each new image detection.
On the other hand, the scenes are interrupted as soon as the image of the anchor is no longer visible by the camera.
I am using xcode 13.1
I use this simple code :
import RealityKit
class ViewController: UIViewController {
#IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
guard let anchor2 = try? Enigme1.loadDebut() else { return }
arView.scene.anchors.append(anchor2)
}
}
Thank you very much for the help you could give me.
The behavior style of Reality Composer's and RealityKit's AnchorEntity(.image) is the same as ARKit's anchor in ARImageTrackingConfiguration – if a tracked image is no longer visible in a view, there will be no ARImageAnchor, thus, there will be no 3D model.
When using AnchorEntity(.image), if your 3D model has more than 100,000+ polygons, every time it reappears on the screen it will cause a slight freeze.

Random image generator causing memory issues

I have a random image generator within an app, however after 5/6 images have been shown in an image view, the apps memory usage is very high causing the didReceiveMemoryWarning() to run. However when the button is pressed quickly the app crashes.
At the start of the app
After 5 or 6 images have been generated
After didReceiveMemoryWarning() has been called
The code that creates the images is
#IBAction func RandomImage(_ sender: Any) {
let randomIndex = Int(arc4random_uniform(UInt32(56)))
imageView.image = UIImage(named: "image\(randomIndex)")
}
with the average image size being shown 600kb.
Is there a way to use or clear the memory more efficiently? Or am I miss using the UIimageView? Would it be best practise to load the image from a data object?

Auto layout only returning single device width. Expecting device that is being used width

I'm trying to set my UIImageView corner radius to produce a circular UIImageView. However, when I run my app on an iPhone 7 Plus the image isn't quiet circular.
imageOutlet.layer.cornerRadius = imageOutlet.frame.size.width / 2
While debugging this issue, I noticed that the width returned was the same regardless of the device. Then, when I changed the "view as: iPhone 7 (w C, h R)" near the bottom of the storyboard to iPhone 7 Plus, all worked as expected on iPhone 7 Plus and did not work correctly on iPhone 7.
My constraints for the UIImageView used are as follows:
My intention is to be able to get the width of the UIImageView as it is on the device that is being used.
Add width/height constraints on the UIImageView to force them to be equal. If the width/height of the image is dependent on the screen size, you will get weird results like you described. Since you have a trailing/leading constraint of 42 pixels to the Superview, the width of the image is going to be different depending on the device. The formula you used only works with equal width/height.
After wrestling with this problem for a while I have finally found a solution.
Summary: Calling layoutIfNeeded() on my UIImageView outlet before calling .frame.size.width yields the correct width for the device that is running the application.
Details:
My setAppearance() function is called in the viewDidLoad() function. During viewDidLoad() call, the application returned a width that was based on the default device (in my case: iPhone 7). This happened even when I was running on the iPhone 7 Plus simulator. However, calling width anytime after viewDidLoad() yielded the correct width based on the device that was running the application.
Below, i'm running the application on an iPhone 7s Plus and printing the width during the viewDidLoad function. The width changes from 281.0 (iPhone 7 expected size) to 310.6667 (iPhone 7 Plus expected size) when called again, after the viewDidLoad() fn.
This results in unsatisfactory as my image is not completely circular (my intention with the .frame.size.width/2 call).
However, calling layoutIfNeeded() fn right before accessing the width member of my UIImageView yields the following width during the viewDidLoad() fn.
By forcing the layout of the UIImageView with layoutIfNeeded() before accusing the width, the application receives the correct width based on the device during the viewDidLoad function.
visit https://developer.apple.com/reference/uikit/uiview/1622507-layoutifneeded for more information.

iOS 8 GPUimage crash in custom photo extension

In my finishContentEditingWithCompletionHandler method for my photo editing extension I am able to correctly filter with GPUimage and save images that are NOT taken by the camera. But when I take a picture with the camera and then use my photo editing extension and hit "Done" the extension just sits there on a blank screen with the activity spinner going. Has anyone else encountered this issue? I am using GPUImage to filter my images.
I have had similar issues with my custom photo extension. Through some investigation, I found that only images with UIImageOrientation.Up would be filtered correctly and written back correctly. I ended up removing the orientation information for the UIImage and it works for me for all image orientations.
// Remove orientation information
UIGraphicsBeginImageContextWithOptions(finalFilteredImage.size, true, finalFilteredImage.scale)
finalFilteredImage.drawInRect(CGRectMake(0, 0, finalFilteredImage.size.width, finalFilteredImage.size.height))
let finalImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();

Image displayed upside down in mac preview, but displayed right side up in the browser

A jpg is rendered upside down on my mac but correctly in a safari browser on the same mac. What is the orientation data that is not correctly being read? Is it in the EXIF?
Here's how to display it with the correct orientation
if (image.imageOrientation != UIImageOrientationUp)
{
image = [UIImage
imageWithCGImage: image.CGImage
scale: 1
orientation: UIImageOrientationUp];
}
based on an answer by ravin Save UIImage, Load it in Wrong Orientation

Resources