UIImagePickerController bottom gets cut off when I add an overlay View - iphone

Need some help on an issue that is consuming my time. It's probably something really simple and I must be forgeting something. Here it go:
I have an UIImagePickerController in which I add a cameraOverlayView (just an ImageView). The problem is that the bottom bar gets cropped by some pixels. When I remove the overlay it works fine. I have even tried to change the overlay frame so that it fits the screen, the image is just the size of the camera viewport, but this happens even with small images. Here is some code:
UIImagePickerController* cam = [[UIImagePickerController alloc] init]; cam.sourceType = UIImagePickerControllerSourceTypeCamera;
cam.delegate = self;
UIImageView *overlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"silhueta.png"]];
overlay.frame = CGRectMake(0, 0, [UIImage imageNamed:#"silhueta.png"].size.width, [UIImage imageNamed:#"silhueta.png"].size.height);
cam.cameraOverlayView = overlay;
[overlay release];

Try to set the contentMode of your UIImageView to i.e. UIViewContentModeCenter.

Related

How to reset the background of a UIView

After adding a background (image) to my UIView (View_0) I wish to implement a button to remove the same background.
How can I do it? I have tried to set a different image as the background of View_0 but this does not work (I suspect this background is set behind "image").
I don't want to use
[View_0 removeFromSuperview];
as I need View_0 to still be there for other purposes....
//Create an ImageView
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 940, 422)];;
//Add the ImageView as the background of the View_0
[View_0 addSubview:image];
//Move custom image behind View
[View_0 sendSubviewToBack: image];
//Failed attempt to remove the background....
View_0.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"defaultImage.PNG"]];
You have added a UIImageView to the View and Not the background of the view. So what is happening is that when u implement
View_0.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"defaultImage.PNG"]];
The background of the View is being set but the UIImageView is now on top of the View so that is why the background of the View is not being shown.
Instead if you simply want to add the background you can change it to the Action of the UIButton.
Also if you use [View_0 removeFromSuperview]; you are trying to remove the view which is not right.
//Create an ImageView
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 940, 422)];;
image.tag = 1234;
//Add the ImageView as the background of the View_0
[View_0 addSubview:image];
//Move custom image behind View
[View_0 sendSubviewToBack: image];
UIImageView *imgView = [self.view viewWithTag:1234];
[img setImage:nil];
This should work i think

remote pinimage on an iphone mapview

i want to display remote images as pins on my map view i tried this way but this dont work
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"here the image URL"]];
imageNamed takes a file from your local application bundle.
You want:
UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:#"here is the image URL"]]];
I don't recommend doing it this way though because it'll block the main UI thread. You should consider loading the image data for your pin asynchronously first.

how to display images in imageview in iphone

Iam new to iphone currently my problem is
i displayed 6 images in 6 image views It was not showing images in imageview I think the imageviews are in large size
i implement code like this.
imageview1 = [[UIImageView alloc] init];
UIImage *img1 = [UIImage imageNamed:#"wolf.jpg"];
[imageview2 setImage:img1];
so plz send me correct code for this imageview.
Thank u in advance.
bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,480,300)];
bgImage.image = [UIImage imageNamed:#"Default.png"];
[self.view addSubview:bgImage];
Also check have you add image file to your project, by Add - > Existing File
First of all, you're adding the image 1 to imageview 2 - are you sure you want to do this?
Secondly, you need to add the imagview to the view hierarchy, for example by adding it to a ViewControllers view, like this: [[self view] addSubview:imageview1] (If this code is situated within the View Controller class).
imageview1 = [[UIImageView alloc] init];
imageview1.image = [UIImage imageNamed:#"wolf.jpg"];

Why does UITableViewCell backgroundView blur an image

I am subclassing a UITableViewCell and in the init function I am doing the following:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"packagelistcell_background.png"]];
[imageView setFrame:CGRectMake(0, 0, 300, 81)];
self.backgroundView = imageView;
[imageView release];
When that displays on the screen, the image appears slightly blurred. For testing, I placed a straight UIImageView above the table view and the image looks perfect and crisp. The table view is a grouped table view. Do you know why it is blurring the image?
I think the cell has been resized and so is the backgroundView.
Try
imageView.autoresizingMask = UIViewAutoresizingNone;
Try shifting the imageView by 0.5 pixels.
Unfortunately #freytag's solution didn't work for me.
To solve this problem I had to add the UIImageView to a UIView container and set this last as background view of my Custom Cell instead of setting directly the UIImageView:
UIImageView *imgView = [[UIImageView alloc] initWithImage:#"cellBackground.png"];
UIView *backgrContainer = [[UIView alloc] initWithFrame:self.backgroundView.frame];
[backgrContainer addSubview:imgView];
[self setBackgroundView:backgrContainer];// instead of [self setBackgroundView:imgView];
[backgrContainer release];
[imgView release];
For some reason setting directly the UIImageView makes it blurry (even if no resize ocurrs). Setting autoresizingMask = None or contentMode <> ScaleToFill for the UIImageView did not fix my problem.
Also beware of the UITableView style, since using a Grouped Style will result in less width for the cell's background view, and this can also resize the image.
( Retina device/simulator doesn't seem to have this problems about blurry image in the cell backgroundVIew)

Overlaying image above UIScrollView's tiledlayer

My iPhone app shows the user some massive images, I've successfully tiled them and used a UIScrollView to allow them to pan around and look at parts of it in detail. Now I want to draw points above that background image and have them move around when the user pans/zooms, essentially like placing a pin on a notice board. I don't want to mark the image permanently and I may need to move it or add more of them. My first attempt id the code below, thinking I could just plonk it into a subview at it would appear in the corner, then I'd worry about offsetting it from the origin and stuff like that. Using this code I can't see my marker anywhere within the UIScrollView so I'm looking for help.
myContentView = [[UIView alloc] initWithFrame:imageRect];
UIImageView *imageView = [[UIImageView alloc] initWithImage:marker];
[myContentView.layer addSublayer:tiledLayer];
[myContentView addSubview:imageView];
What I would do is make another UIView *mapView that is the same size as myContentView to hold the tiledLayer, and have both the imageView and new mapView at the same level instead of one being a subview of the other.
myContentView = [[UIView alloc] initWithFrame:imageRect];
UIView *mapView = [[UIView alloc] initWithFrame:imageRect];
[mapView addSublayer:tiledLayer];
[myContentView addSubview:mapView];
UIImageView *imageView = [[UIImageView alloc] initWithImage:marker];
[myContentView addSubview:imageView];