iOS light linen background? - ios

I really want to know if there's a way to get iOS's light linen background. Here's what it looks like:
Is there a way to access this by merely using the built-in SDK? Or do I have to find an image like this somewhere?
EDIT: I didn't want to use private APIs, so here's what I did. I grabbed the image this way:
CGRect rect = CGRectMake(0.0f, 0.0f, 640.0f, 960.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor underPageBackgroundColor] CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagepath = [documentsDirectory stringByAppendingPathComponent:#"underPageBackground.png"];
[UIImagePNGRepresentation(image) writeToFile:imagepath atomically:YES];
And here is the resulting png in retina resolution: (click on thumbnail to open)
Hope this is useful to someone. :)

Use [UIColor underPageBackgroundColor]. And here is a link with useful information and samples.

I'm not sure it is exactly the one (seems darker to me) but, you can choose the "Scroll View Textured Background Color" in Interface Builder. To do so, when selection a color choose the dropbox to the right instead of the color box on the left.

I believe you should be able to find this background in the SDK(it should be the default one for this kind of "flick page up" function) or on google (try looking for UIStockImageUnderPageBackground.png).
Otherwise - it looks like a pattern. What you could do is to import the attached screenshot, then cut a bit without the shadows and fill a blank canvas with it, so that the sides match forming the original pattern.

This isn't really a solution to get the actual image but you can easily just make the texture. I just pulled up a tutorial on how to make it in photoshop. iOS Linen tute here
This way you can make it whatever color you want!

Related

Best way to manage image orientation?

I am trying to set different images on a UIImageView but I don´t know how to handle the image orientation because always that I call image.imageOrientation the result is UIImageOrientationUp and it isn´t.
Here some examples:
Image with wrong orientation.
Image with wrong orientation.
I want that all images look correctly but I don´t know how to do it if the image.imageOrientation don´t give me the correct value.
Here my code:
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:#"porfileImage.png"];
UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
if (img == nil) {
img = [UIImage imageNamed:#"user"];
}
NSLog(#"Orien: %ld",(long)img.imageOrientation);
self.porfileImage.image = [UIImage imageWithCGImage:[img CGImage] scale:[img scale] orientation: UIImageOrientationUp];
I found my error!!
I was saving the image using UIImagePNGRepresentation(image); so the image lose the orientation and when I wanted to use it, the image already was a default orientation that isn´t the correct one.
The solution is to use UIImageJPEGRepresentation(image, 1.0); instead of UIImagePNGRepresentation(image); and for automatically the image save with the correct orientation.
Nearly all the images clicked by a camera have metadata/ EXIF data which has the image orientation value. As the image is transmitted or passed along various channels like email, messaging etc. some of this data might be stripped off. So every time you load the image using CGImage, it takes the default orientation of UIImageOrientationUp.
One solution might be to create two versions of your image, UIImage and CGImage, and compare their height. If they are equal, then the CGImage version is not be rotated and you are good. Else, the CGImage conversion has messed up the orientation. In that case, swap the x/y coordinate of origin and try to rotate it.

Image is not showing according to the frame of UIImage after zooming and rotating

I add pinch to zoom and rotate gestures to UIImageView (myImageView). After zooming and rotating, there is apply button to save the image. Below is the apply method. It saves the image correctly with exact rotation and scaling . As it is just like screenshot.
UIGraphicsBeginImageContextWithOptions(view.frame.size,view.opaque,0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data=UIImageJPEGRepresentation(viewImage, 100);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *strPath = [documentsDirectory stringByAppendingPathComponent:#"BorderedImage.jpg"];
[data writeToFile:strPath atomically:YES];
But after doing this , i reassign the saved image to myImageView.
myImageView.image=[self loadImage:#"BorderedImage.jpg"];
what it does, if image was zoomed out , image becomes more small, if image was zoomed in , image becomes too big. if image was rotated, then image shows with totally wrong rotation .
I know this is some kind of UIImageView problem, because i checked the image in documents folder , it is same just like when i press apply button.
i am new to iOS development . kindly help me out.
After a great headache , i solved it myself. just before re-assigning the transformed image, i change the UIImageView transform to the original transform values.
myImageView.transform=defaultTranform;
where defaultTransform is
CGAffineTransform rotTran;
rotTran=myImageView.transform; // view did load

UIImage manipulation IOS

In Order to create a matrix and manipulate the pixels of the image, should i convert the image to bitmap?
My application is about taking a picture from camera or library and when i touch a part of the image , this region of the image should stretch.
Here is the code that i tired to convert the UIImage to bitmap:
UIEdgeInsets edgeInsets = UIEdgeInsetsMake(-20, -20, -20, -20);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
imageView.image = [[UIImage imageNamed:#"number1.png"] resizableImageWithCapInsets:edgeInsets];
[self.view addSubview:imageView];
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0.0);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *bmImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSArray *documentsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentsPaths objectAtIndex:0];
[UIImagePNGRepresentation(bmImage) writeToFile:[documentsDir stringByAppendingString:#"num1.png"] atomically:YES];
Thanks for your help
The right approach to your problem is tessellating the image and then distorting the tessellation grid. This is a common technique in computer graphics (e.g. with OpenGL).
You can either try that yourself or use an existing specialised framework like GPUImage. It offers a lot of filters and distortion effects pre-made. Just go to the linked page and search the page for "distortion". You have pinch distortion, swirl distortion, bulge distortion, and so on.
You will possibly need to get one of those classes and modify it a bit so that the effect is applied around a moving center, but that should not be that difficult.
BTW: what you are doing in your code in not really useful, since you already have a UIImage, so you do not need to put it in a UIImageView and render the view into a bitmap context to come out with another UIImage.

iOS 5: adding a caption to a camera image

I am building a simple app that allows the user to take photos that will be saved in the photo album. Because I expect users will be taking a lot of images of objects that look similar but not the same (for example, details of pieces of furniture in a house), I would like to add a small text caption on the image itself to describe the content of the image.
Not worrying about how the user will enter this text at the moment, can anyone give me some advice as to how I can add some text to an image taken with the UIImagePickerController?
Create a new graphics context.
Draw the image into the context.
Draw the text over it.
Create a new image from the context.
The code should be something like this:
UIGraphicsBeginImageContextWithOptions(sourceImage.size, YES, sourceImage.scale);
[sourceImage drawAtPoint:CGPointZero];
NSString *caption = #"Hello World";
UIFont *captionFont = [UIFont boldSystemFontOfSize:24.0];
[[UIColor whiteColor] setFill]; // or setStroke? I am not sure.
[caption drawAtPoint:CGPointMake(10.0f, 10.0f) withFont:captionFont];
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Font smoothing/anti-aliasing when using Quartz2d on iOS?

I have a custom UIView that generates some kind of diagram that needs a height notated with a number.
All drawing goes ok, it antialiases correctly when creating circles etc. with quartz2d.
However, when I want to draw a NSString to the context, the font-smoothing/anti-aliasing is messed up. Disabling anti-aliasing does result in a thinner text, so the switch does work, however, the anti-aliased text is awfull. It doesn't look as crisp at all as the normal text rendered in iOS.
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetShouldAntialias(context, YES);
CGContextSetShouldSmoothFonts(context, YES);
NSString *stringValue = [NSString stringWithFormat:#"%d", input.height];
UIFont *font = [UIFont systemFontOfSize:textsize];
[stringValue drawAtPoint:CGPointMake(x, y) withFont:font];
I am out of clues on how to solve this font rendering issue. Any ideas?
If you are willing to forego the anti-aliasing on the text you could save the context with anti-aliasing turned on.
GCContextSaveGState(context);
Turn anti-aliasing off and render the text:
GCContextSetShouldAntialias(context, NO);
NSString *stringValue = [NSString stringWithFormat:#"%d", input.height];
UIFont *font = [UIFont systemFontOfSize:textSize];
[stringValue drawAtPoint:CGPointMake(x, y) withFont:font];
Then restore the graphics context back to it's previous space. (with anti-aliasing turned on) to render the remaining parts of the drawing.
CGContextRestoreGState(context);
My solution to this problem was to just add several UILabel programmatically with the right coordinates. These UILabel instances rendered the text perfectly, so this solved my problem.

Resources