Retina Image show 1/4th size in cocos2d ios6 - iphone

i researched so much about that but i cant find anything interesting.. actually i had a project in cocos2d made in ios5 and show images size good either in retina .. when upgraded to ios6 it shows one fourth image sizes.. It shows Retina display ON in CCDirector.

I Think this will helps you.
NSString *iPadtext;
NSString *device = [UIDevice currentDevice].model;
NSLog(#"deive name is %#",device);
Add both images like pause.png and pause-hd.png
if([device isEqualToString:#"iPad"] || [device isEqualToString:#"iPad Simulator"] ){
iPadtext = #"-hd";
}
CCMenuItemImage *pauseMenuItem = [CCMenuItemImage
itemFromNormalImage:[NSString stringWithFormat:#"pause_01%#.png",iPadText] selectedImage:[NSString stringWithFormat:#"pause_01-over%#.png",iPadText]
target:self selector:#selector(PauseButtonTapped:)];
i hope it will help you

Related

Switch On/Off flash while recording the Video in iphone app

I am recording video from my iPhone app.
I am using an overlay over the camera and placed a button in the overlay. I want to know with the help of which function can I turn camera's flash on/off while the video is being recorded.
How can I set a flash button in the camera overlay?
If you are using AVFoundation for video recording, You should first check if device has torch/flash because torch is available when video is being recorded from the back camera, you can not have the torch/flash when using front camera.
using something like this
- (BOOL) hasTorch
{
return [[[self avCaptureDeviceInput] device] hasTorch];
}
and then set the torch accordingly using AVCaptureTorchMode
- (void) setTorchMode:(AVCaptureTorchMode)torchMode
{
AVCaptureDevice *device = [[self videoInput] device];
if ([device isTorchModeSupported:torchMode] && [device torchMode] != torchMode) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setTorchMode:torchMode];
[device unlockForConfiguration];
} else {
id deleg = [self delegate];
if ([deleg respondsToSelector:#selector(acquiringDeviceLockFailedWithError:)]) {
[deleg acquiringDeviceLockFailedWithError:error];
}
}
}
}
if you follow the AVCam Demo from Apple you will get your answers basically.
Assuming you are using UIImagePickerController (from your tag), use the cameraFlashMode provided by UIImagePickerController to control the flash.
You can set its value to UIImagePickerControllerCameraFlashModeOff, UIImagePickerControllerCameraFlashModeAuto or UIImagePickerControllerCameraFlashModeOn. Default is auto.

iPhone 5's low light boost mode

Has anyone been able to get the iPhone 5's new low light boost mode to work in their custom camera app? I tried the following code, but noticed no difference - whereas the native camera app significantly boosted the brightness.
if ([[captureManager backFacingCamera] isLowLightBoostEnabled]) {
[[captureManager backFacingCamera] automaticallyEnablesLowLightBoostWhenAvailable];
}
You need to lockForConfiguration, according to the docs (well, the header file):
if ([[self backFacingCamera] respondsToSelector:#selector(isLowLightBoostSupported)]) {
if ([[self backFacingCamera] lockForConfiguration:nil]) {
if ([self backFacingCamera].isLowLightBoostSupported)
[self backFacingCamera].automaticallyEnablesLowLightBoostWhenAvailable = YES;
[[self backFacingCamera] unlockForConfiguration];
}
}
Also, isLowLightBoostEnabled tells you whether or not the low light is actually being boosted, not whether it can be. That's the isLowLightBoostSupported selector, as above (to which only iOS 6 devices respond).

New image name for iPhone 5

With the retina we make images with the #2x in the name. I see where the default image has to be default-568h#2x but this does not seem to be the case for other images. Like if my background is bg.png and bg#2x.png I tried using bg-568h#2x.png but that does not work. Can somebody tell me what the images need to be named to support the iPhone 5?
No special suffix for iPhone 5 (4'' display), just the specific Default-568h#2x.png file.
Here's a macro to handle it:
// iPhone 5 support
#define ASSET_BY_SCREEN_HEIGHT(regular, longScreen) (([[UIScreen mainScreen] bounds].size.height <= 480.0) ? regular : longScreen)
Usage: (assets names - image.png, image#2x.png, image-568h#2x.png)
myImage = [UIImage imageNamed:ASSET_BY_SCREEN_HEIGHT(#"image",#"image-568h")];
There is no specific image name. Having the Default-568h#2x will launch that image on an iPhone 5 or iPod Touch 5G and will enable the non-letterbox mode. After that, you need to design your views to be flexible. There is no special "image name" or anything for the new size.
For your background, for example, you should probably be using an image that is capable of stretching or tiling and have it configured properly before setting it.
iPhone 5 does not have a different pixel density, it's the same retina display PPI as the iPhone 4/4S, it's just a different screen size. The #2x images will be used on iPhone 5 as well as 4/4S.
To complete Jason's answser, I would propose: What about overriding the UIImage's imageNamed: method to have it happen the "-568" suffix to the name of your image? Or add a new method called resolutionAdaptedImageNamed: to the UIImage maybe using a category.
If I have a bit of time in the next days, I will try to post the code for that.
Caution: will not work for images in the Nib files.
If you are using Xcode 5, you can use asset catalog (see usage there Apple's documentation)
Once your asset catalog is created [ UIImage imagedNamed: #"your_image_set" ] will pull right image based on device.
You can also make category for this just make category as below .
UIImage+Retina4.h
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#interface UIImage (Retina4)
#end
UIImage+Retina4.m
#import "UIImage+Retina4.h"
static Method origImageNamedMethod = nil;
#implementation UIImage (Retina4)
+ (void)initialize {
origImageNamedMethod = class_getClassMethod(self, #selector(imageNamed:));
method_exchangeImplementations(origImageNamedMethod,
class_getClassMethod(self, #selector(retina4ImageNamed:)));
}
+ (UIImage *)retina4ImageNamed:(NSString *)imageName {
// NSLog(#"Loading image named => %#", imageName);
NSMutableString *imageNameMutable = [imageName mutableCopy];
NSRange retinaAtSymbol = [imageName rangeOfString:#"#"];
if (retinaAtSymbol.location != NSNotFound) {
[imageNameMutable insertString:#"-568h" atIndex:retinaAtSymbol.location];
} else {
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
if ([UIScreen mainScreen].scale == 2.f && screenHeight == 568.0f) {
NSRange dot = [imageName rangeOfString:#"."];
if (dot.location != NSNotFound) {
[imageNameMutable insertString:#"-568h#2x" atIndex:dot.location];
} else {
[imageNameMutable appendString:#"-568h#2x"];
}
}
}
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageNameMutable ofType:#"png"];
if (imagePath) {
return [UIImage retina4ImageNamed:imageNameMutable];
} else {
return [UIImage retina4ImageNamed:imageName];
}
return nil;
}
#end
And you can directly check using import this category as below where you wont to check 568 or normal image
imgvBackground.image=[UIImage imageNamed:#"bkground_bg"];//image name without extantion

how to know is it iphone or ipad?

i want to know the user uses the iphone or ipad,if the user uses the iphone i want to open the camera,if he uses the ipad or runs in simulator i want to open the library. how it is possible?
how to find the details of devices?
how to know current using device by user through xcode?
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:#"iPhone"])
{
//your code
}
.....
Hope this helps.
EDIT:
See this thread -determine-device-iphone-ipod-touch-with-iphone-sdk .
[[UIDevice currentDevice].model hasPrefix:#"iPhone"]
Use the "hasPrefix" so that it works in simulator.
You should not determine whether there is a camera by looking at the model. This is not future proof - for instance, you would not be supporting the iPad 2's camera.
UIImagePickerController has a special method to determine whether a camera in available:
+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
With sourceType being one of
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
Make use of this to identify devices.
// If iPhoneOS is 3.2 or greater then __IPHONE_3_2 will be defined
#ifndef __IPHONE_3_2
typedef enum {
UIUserInterfaceIdiomPhone, // iPhone and iPod touch
UIUserInterfaceIdiomPad, // iPad
} UIUserInterfaceIdiom;
#define UI_USER_INTERFACE_IDIOM() UIUserInterfaceIdiomPhone
#endif // ifndef __IPHONE_3_2
but if you want to check if camera is available I think you can make use of UIImagePickerController's static method
+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
Working on Vaibhav Tekam's answer, I used this
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType hasPrefix:#"iPhone"])
{
//your code
}
or
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType hasPrefix:#"iPad"])
{
//your code
}
etc.
It's much easier that way as it covers all models.

IPhone iOS 4.3 camera focus square - removeable programmatically?

Since my friend updated his iPhone iOS to 4.3 there's a small square which appears every time he takes a picture with the camera.
We're developing an app that uses the camera and would like to remove this annoying square. I didn't find anything about it in Apple's UIImagePickerController documentation.
The square didn't exist in former iOS versions.
You may want to try to lock the focus to disable auto-focus. Here is a sample code:
NSArray *devices = [AVCaptureDevice devices];
NSError *error;
for (AVCaptureDevice *device in devices) {
if (([device hasMediaType:AVMediaTypeVideo]) &&
([device position] == AVCaptureDevicePositionBack) ) {
[device lockForConfiguration:&error];
if ([device isFocusModeSupported:AVCaptureFocusModeLocked]) {
device.focusMode = AVCaptureFocusModeLocked;
NSLog(#"Focus locked");
}
[device unlockForConfiguration];
}
}
Setting the .showsCameraControls property of your picker controller to NO should remove the focus square (it did pre 4.3, I don't think anything has changed), but the downside is you'll need to provide your own controls (to take photos, etc). It's all or nothing I'm afraid!
Create a custom overlay and default overlay will not display. You can make your overlay can be completely empty.