UIImage not displayed - ios

I am using iOS 7 SDK and Xcode 5. I want to set icons on UITabBarItem. I am using below method.
setFinishedSelectedImage: withFinishedUnselectedImage:
It was working till now. But suddenly it stopped displaying images.
I tried below various options :
[img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[tabBarItem setSelectedImage:img];
[tabBarItem setImage:img];
[[UITabBarItem alloc] initWithTitle:title image:img selectedImage:img];
None of them is working. Here, img is the image downloaded from URL.
Then I tried with one of the images in app resource and it was displaying.
After that, I tried using temporary UIImageView with background color to red and set img to this UIImageView, it displayed red color instead of img.
But strange part is that I use the same img in other view controllers where it is displayed correctly.
Any idea how to solve this issue?

It was my mistake in code. I had to initialze img to some UIImage on declaration.
Below is shown what was the issue.
UIImage * img; // Image not initialized
// This condition was not satisfied and hence `img` was not storing any time.
if (condition)
{
img = ...;
}
// Below condition should have been satisfied if `img` was not initialized.
// But it did not. I am not getting why.
if (!img)
{
NSLog(#"Image is nil");
}
[tabBarItem setImage:img];

Related

Conflicting UIBarbuttonItem's tintcolor and image

I have a UIToolbar in one of my VCs, it has 3 color buttons which changes the color of my drawing. Anyways I want to change the button's image when its selected. The images are shown below, the problem is apparently the button's "tintcolor" is messing with the original image.
If i set the "tintcolor" to red my active button looks like a bigger red circle, if its "clearcolor" it doesn't show. Any help would be much appreciated guys.
UIImage *image = [UIImage imageNamed:#"red-selected"];
[button setImage:image];
I even tried:
UIImage *image = [[UIImage imageNamed:#"red-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[btn setImage:#"red-selected.png" forState:UIControlStateNormal];
you can also do it in the interface builder - indicates a photo for selected mode.
pay attention the type of the photo- is it png?
try #"red-selected.png"/ #"red-selected.jpg"

GPUImage output image is missing in screen capture

I am trying to capture screen portion to post image on social media.
I am using following code to capture screen.
- (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
Above code is perfect for capturing screen.
Problem :
My UIView contains GPUImageView with the filtered image. When I tries to capture screen using above code, that particular portion of GPUImageView does not contains the filtered image.
I am using GPUImageSwirlFilter with the static image (no camera). I have also tried
UIImage *outImage = [swirlFilter imageFromCurrentFramebuffer]
but its not giving image.
Note : Following is working code, which gives perfect output of swirl effect, but I want same image in UIImage object.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
GPUImageSwirlFilter *swirlFilter = [GPUImageSwirlFilter alloc] init];
swirlLevel = 4;
[swirlFilter setAngle:(float)swirlLevel/10];
UIImage *inputImage = [UIImage imageNamed:gi.wordImage];
GPUImagePicture *swirlSourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage];
inputImage = nil;
[swirlSourcePicture addTarget:swirlFilter];
dispatch_async(dispatch_get_main_queue(), ^{
[swirlFilter addTarget:imgSwirl];
[swirlSourcePicture processImage];
// This works perfect and I have filtered image in my imgSwirl. But I want
// filtered image in UIImage to use at different place like posting
// on social media
sharingImage = [swirlFilter imageFromCurrentFramebuffer]; // This also
// returns nothing.
});
});
1) Am I doing something wrong with GPUImage's imageFromCurrentFramebuffer ?
2) And why does screen capture code is not including GPUImageView portion in output image ?
3) How do I get filtered image in UIImage ?
First, -renderInContext: won't work with a GPUImageView, because a GPUImageView renders using OpenGL ES. -renderinContext: does not capture from CAEAGLLayers, which are used to back views presenting OpenGL ES content.
Second, you're probably getting a nil image in the latter code because you've forgotten to set -useNextFrameForImageCapture on your filter before triggering -processImage. Without that, your filter won't hang on to its backing framebuffer long enough to capture an image from it. This is due to a recent change in the way that framebuffers are handled in memory (although this change did not seem to get communicated very well).

Setting an background image over an image set for a UIImageView - Objective C

I am setting images to a UIImage programmatically. But I want to also add a play button over that view. Think of Facebook in how there is a play button over the image. That is exactly what I am trying to figure out on what to do. Here is my setting of the UIImage:
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg", indexPath.row]];
cell.photoView.image = img;
Suggestions, thoughts?
You can add playbutton either as a UIButton or a UIImageView and add as a subview to your photoview.
[cell.photoView addSubview:urPlayButtonView];

iOS app - Apply background image object to UIView

Can anyone help me understand how I apply a background image object to a UIView please?
I have created a background image which is a blurred version of a background and I would like to apply it to be the background of a uiView in the foreground which would ideally mask the background image.
I have the following code so far -
_blurImage = [source stackBlur:50];
[_HPBlurView.backgroundColor = [UIColor colorWithPatternImage:[_blurImage]]];
I would like to apply the image object(_blurImage) to be the background image of _hpBlurView but i'm struggling to get it working!
At first glance, you are using too many brackets. Here is a working version of your code :
_burImage = [source stackBlur:50];
_HPBlurImage.backgroundColor = [UIColor colorWithPatternImage:_blurImage];
I can't see what stackBlur:50 returns. So start from the beginning. colorWithPatternImag takes UIImage as a parameter. So Start by adding a picture, any picture, to your application. Lets imagine that the image is called image.png. This is one way to do it:
UIImage *image = [UIImage imageNamed:#"image.png"];
_HPBlurView.backgroundColor = [UIColor colorWithPatternImage:image];
This should help to get you going.
Create an image and add to the background.:
UIImage *image = [UIImage imageNamed:#"youimage"];
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
It's that.
To make sure everything resizes properly, no matter rotation, device size and iOS version, I just set an UIImageView
//Create UIImageView
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.frame]; //or in your case you should use your _blurView
backgroundImageView.image = [UIImage imageNamed:#"image.png"];
//set it as a subview
[self.view addSubview:backgoundImageView]; //in your case, again, use _blurView
//just in case
[self.view sendSubviewToBack:backgroundImageView];

How to retrieve image locally from application and display it on UIImageView with Objective-C

I have loaded the image in application's folder that is source
but I could not find the code by which I will display that image
on UIImageView using button click event. Please help me out for this.
I have used this following code before:
UIImage *img = [UIImage imageNamed:#"xyz.png"]
but I could not set the UIImageView image to img in the method
Then please help me with code to set the UIImageView image to img in the method I call on my button click.
You can get an image added to your project folder/subfolder using
UIImage *img = [UIImage imageNamed:#"xyz.png"]
Then set the UIImageView image to img in the method you call on your button click.
Drag the image into Xcode and then set up an UIImage variable like this:
UIImage *theImage = [UIImage imageNamed:#"theImage.png"];
then implement it into your UIImage view by 'myImageView.image = theImage;
Make sure you have IBOutlet set up to your image view, though. The easiest way is to just drag the image into Xcode and select it under the popup list in Interface Builder.

Resources