Background image not fit to the screen - iphone

Here in my app i used the background image size as 320 x 480,but in the end of the screen some portions not visible,here my code
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"ibg.png"]];
Please help me to solve to make the image screen fit..

If the invisible portion has height equal to 50 pixel, then could you please try resize your image (ibg.png) to 320 x 430 using
- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size {
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return destImage;
}
after that
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"ibg.png"]];
should make it, hope it help, please give me a feedback, thanks.

Your image may be offset by the status bar, which takes up 20 pixels (or 'points') of space at the top of the screen. If your status bar is visible, the Y position of your full-screen background image must be -20 rather than 0.

Related

Display Top Portion of UIImageview

I'm trying to display a top portion of an UIImage.
I know I can use the following code and display the middle portion. I'm just trying to figure out how to do the same for the top portion:
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
The UIImage I get from the server is not necessarily the same size, so I cannot use UIViewContentModeTopLeft. I want a way to scale the image and show the top portion.
Thanks.
You want to display an arbitrary rectangle of your image, so the easiest way to go will to be to put your imageView inside a regular view. You can set the frame of the image view to display the bit you want and set the enclosing view to do the clipping.
e.g. you have a 1000 x 1000 px image and you want to display the rectangle 200,200 to 400,400
UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"SomeImage"]];
imageView.frame = CGRectMake( -200, -200, 1000, 1000);
UIView* enclosingView = [[UIView alloc] initWithFrame:CGRectMake( 0, 0, 200, 200);
enclosingView.clipsToBounds = YES;
[enclosingView addSubview: imageView];
Content mode doesn't matter much in this case, since you're setting the dimension of the image view to match the image.
One way is to call CGImageCreateWithImageInRect on your original image to create a new image with just the top portion.
Something like:
CGImageRef newImageRef = CGImageCreateWithImageInRect( oldImage.CGImage, CGRectMake(0,0,50,50) );
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
CGImageRelease( newImageRef );
then display newImage rather than oldImage.

When taking snap shot there is a showing very little bit white background color

There are Two View controllers in one view controller i am taking an snap shot and in the anothe view controller i am showing tha anap shot that was picked.
I am working on image, i need to take a snap shot while i am doing this i am getting white background. I do not know why this appears? As below image (There are Three image views , Initially image view has a transparent image view then background body image view and tattoo image view.)
When i am taking the screen shot I am hiding the Background image.
i set the view alpha to 1.0f, i set the view background color to clear color
The output screen shot is
My code is
self.backgroundImgView.hidden=YES;
self.view.backgroundColor=[UIColor clearColor];
self.view.alpha=1.0f;
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGRect rect;
rect = CGRectMake(appDelegate.xFloat, appDelegate.yFloat, appDelegate.widthFloat, appDelegate.heightFloat);
CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], rect);
UIImage *img = [UIImage imageWithCGImage:imageRef];
appDelegate.tattooImg=img;
CGImageRelease(imageRef);
Make a UIView like a holderview.... on the self.view. Then add both the images on the holderview not the self.view.... then wen u save the screenshot take it of the holderview ...

How to show in UIImage just a part of image?

I have UIImageView in which I'm showing 50x100 image.
I want to show only a part of image 50x50 (top part)?
How can I do that?
The very simple way to move big image inside UIImageView as follows.
Let we have the image of size (100, 400) representing 4 states of some picture one below another. We want to show the 2nd picture having offsetY = 100 in square UIImageView of size (100, 100).
The solution is:
UIImageView *iView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
CGRect contentFrame = CGRectMake(0, 0.25, 1, 0.25);
iView.layer.contentsRect = contentFrame;
iView.image = [UIImage imageNamed:#"NAME"];
Here contentFrame is normalized frame relative to real UIImage size.
So, "0" means that we start visible part of image from left border,
"0.25" means that we have vertical offset 100,
"1" means that we want to show full width of the image,
and finally, "0.25" means that we want to show only 1/4 part of image in height.
Thus, in local image coordinates we show the following frame
CGRect visibleAbsoluteFrame = CGRectMake(0*100, 0.25*400, 1*100, 0.25*400)
or CGRectMake(0, 100, 100, 100);
You can crop the image by using CGImageCreateWithImageInRect, which is Quartz primitive working on CGImageRef, so you would have something like:
CGImageRef imageRef = CGImageCreateWithImageInRect(originalImage.CGImage, cropRect);
UIImage* outImage = [UIImage imageWithCGImage:imageRef scale:originalImage.scale orientation:originalImage.imageOrientation]];
CGImageRelease(imageRef);
When calculation cropRect, keep in mind that it should be given in pixels, not in points, i.e.:
float scale = originalImage.scale;
CGRect cropRect = CGRectMake(0, 0,
originalImage.size.width * scale, originalImage.size.height * 0.5 * scale);
where the 0.5 factor accounts for the fact that you want the top half only.
If you do not want to go low-level, you could add your image to a UIView as a background color and use the clipToBounds CALayer property to make the clipping:
myView.backgroundColor = [UIColor colorWithBackgroundPattern:myImage];
myView.layer.clipToBounds = YES;
also, set myView bounds accordingly.
I might have a solution for you. See if this works. In Interface Builder there is an option about Image content fill properties. You can set it to top-left. Follow the image in interface builder -
After this set the size of UIImageView to 50x50 with "clip-subviews" checked...

how to reduce imagesize in iphone

Iam new to iphone currently my problem is
i displayed 6 images in image view It was not showing images in imageview I think the imageviews are in large size
so plz send me code for this imageview.
Thank u in advance.
You could use this for image resizing:
- (UIImage *)rescaleImageToSize:(CGSize)size {
CGRect rect = CGRectMake(0.0, 0.0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
[self drawInRect:rect]; // scales image to rect
UIImage *resImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resImage;
}

Iphone app: Resize a png by getting Height and Width from user

Ive an image with particular resolution appearing on Iphone screen. I need to resize that image by getting info. as an alert from user(Width and height). Cud anyone help me with block of code for this????
WARNING: code typed in answer box, not tested. It's pretty close, though.
NSSize newSize = [self getSizeFromUser]; // you have to write this part.
CGRect theRect = CGRectMake (0, 0, newSize.width, newSize.height);
// Put image into new context
UIGraphicsBeginImageContext (newSize);
[theImage drawInRect: theRect];
//get the image from the context
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
[[compositeImage retain] autorelease];
UIGraphicsEndImageContext();