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

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

Related

NSImage initWithContentsOfURL missing alpha channel when loading TIFFs

In my app I use initWithContentsOfURL to load various types of image (JPEG, TIFF, PNG, GIF, etc) into an image, and then into an OpenGL texture.
The only type that loads an image with an alpha channel is png. (in the list above, only PNG and TIFF can contain alpha data.) If I try to load a .tiff image, it gets loaded without an alpha channel (the image's image rep reports alpha=NO, and it reports bitsPerPixel of 24.
I can edit an image with alpha in PS, save it as a PNG and a TFF, and the PNG loads in my program with alpha but the TIFF does not. Further, I can open the TIFF image in PS and confirm that it does have alpha data.
What am I missing here? Why are my TIFF images not loading with an alpha channel? And is there another appkit call I can make that WILL load my TIFF without dropping the alpha channel on the floor?
EDIT:
Since posting this question I've found that some 4-channel TIFFs load with alpha data and some do not. I have not yet figured out what workflow results in the different results.
This file loads with an alpha channel in Photoshop, but not if you load it in Cocoa using -[[NSImage alloc] initWithContentsOfURL]:
Image "Red Julia Seahorse crop"
A similar image that also has an alpha channel DOES load with alpha using the above Cocoa call:
Image "Transparent Seahorses"
I just tried (OSX 10.9.4) and the image loaded complete with graduated transparency. The code I used is trivial:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSURL *imageURL = [NSURL URLWithString: #"file:/Users/john/Desktop/test.tiff"];
NSImage *image = [[NSImage alloc] initWithContentsOfURL: imageURL];
self.imageView.image = image;
}
I created a TIFF using layers and without layers (two tests). Both worked. I tried a couple of different NSImageView backgrounds to verify the graduated transparency was genuine. (If you choose different Image View border styles in IB the background colour changes too).
I used Photoshop 12 (CS5) to create the images, and manually checked the 'Save Transparency' checkbox in the TIFF Options dialog when saving.
Hopefully something here helps you home in on your issue. From my tests it all works as expected.
The issue is definitely with how the images were saved, most likely the TIFF options used.
Using your two images, the "Red Julia Seahorse Crop" image did not display with transparency, but the "Transparent Seahorses" displayed correctly with transparency.
I opened the "Red Julia Seahorse Crop" in Photoshop and re-saved the image (unchanged), but made sure the "Save Transparency" check box was selected in the "TIFF Options" dialog box. Once saved, that image now showed transparency correctly in the application.

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();

Changing resources programmatically in Objective-C iOS 5 for Retina Display

My app have a background image that fills the screen. I'd like to display the correct .png file depending on if we're on a Retina Display device or not. I already have added all the .png files for both iPhone and iOS with the correct sizes. Is it possible ? If not, how should I handle it properly ?
I have XCode 4.3.2 with iOS 5.1 as the deployment target.
If you name your graphics properly (e.g. add "#2x" to the suffix of the png files), iOS is smart enough to use your Retina display graphics on the appropriate devices & displays. Especially if you are using UIImageViews or controls or whatever, within your user interfaces designed within XIB files.
If you're doing programmatic images (i.e. where you define an outlet and then grab an image via something like "[UIImage imageNamed:], iOS is still smart enough to pick up the high rez images for you. Again, provided you named your graphics properly.
There are other questions here on StackOverflow that might help you out, such as:
How to support both iPad and iPhone retina graphics in universal apps
How to activate #2x high res graphics for retina display?
This probably would work. First it checks if the screen has a retina display, and if it does, sets the background image to the retina image. If it does not have a retina display, the background image is the regular image. You can put this in viewWillAppear or viewDidLoad.
if ([[UIScreen mainScreen] respondsToSelector:#selector(displayLinkWithTarget:selector:)] &&
([UIScreen mainScreen].scale == 2.0)) {
// Retina display
UIImage *backgroundImage = [UIImage imageNamed:#"retinaImage.png"];
} else {
// Non-Retina display
UIImage *backgroundImage = [UIImage imageNamed:#"nonRetinaImage.png"];
}
Hope this helps!

Adding Custom Retina Image To TabBar In iOS5

I am trying unsuccessfully to get my custom retina images to display in my custom iOS5 TabBar.
I have 4 items in my TabBar, I have set the selected/unselected image to contact#2x.png which has a resolution of 160px x 75px. I figured 4 of these 160px width images would accommodate the 640px retina width nicely.
You can view my contact#2x.png here
https://lh4.googleusercontent.com/-afHulbEcxNE/TuPe-YIj91I/AAAAAAAAAII/lCojphAxF9w/s160/contact%2525402x.png
I have set all the items programtically as seen below.
UIImage *selectedContact = [UIImage imageNamed:#"contact#2x.png"];
UIImage *unselectedContact = [UIImage imageNamed:#"contact#2x.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
[item0 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact];
[item1 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact];
[item2 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact];
[item3 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact];
At runtime I can see that the scale is set to 1
Why isn’t the 2 being picked up off the image suffix? The tab bar is huge, and isnt scaled.
Please see the simulator screenshot below…
https://lh5.googleusercontent.com/-A5oxZprlDhU/TuPfAlG_HQI/AAAAAAAAAIc/mIwHXOPZSrE/s735/simulator.png
My other retina images for my app icon and default icon are working.
Thoughts? I am driving myself nuts ☺ Thanks in advance.
JoePasq is wrong, he obviously is not up to date with the latest iOS5 appearance customisation API. Your problem could be that you specified the #2x in the filename, just pass "contact.png" to imagedNamed...
[UIImage imageNamed:# "contact.png"]
Have you looked at the documentation for customizing the appearance of UITabBar?
You should consult this tutorial by Ray Wenderlich about using the UIAppearance APIs.
His code is this:
UIImage *tabBackground = [[UIImage imageNamed:#"tab_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage: [UIImage imageNamed:#"tab_select_indicator"]];`
Note that the customization happens on the Tab bar, not the tab bar items—assuming it’s the same customization for each one.
As nbransby said you do not use #2x in the filename.
Prior unedited answer:
From the documentation:
The images displayed on the tab bar are derived from this image. If this image is too large to fit on the tab bar, it is scaled to fit. The size of an tab bar image is typically 30 x 30 points. The alpha values in the source image are used to create the unselected and selected images—opaque values are ignored.
Your icons should be 30x30 px for normal resolution and 60x60 px for retina resolution. They should also be a solid color, the tab bar adds the coloring.

Galleria thumbnails not displaying correctly

I have a galleria implementation with the Twelve premium theme.
I am having a real problem with the thumbnail rendering on galleries with mixed portrait and landscape images. The thumbnails for the portrait images are being cropped top and bottom, with only the centre showing. The image appears to display OK in lightbox and fullscreen mode but occasionally also appears cropped in the main stage area.
See here for example.
Any idea why this is happening?
Have you tried setting thumbCrop to false in the theme settings?
Galleria.addTheme({
...
defaults: {
...
thumbCrop: false,
}
...
}

Resources