New to ObjC : Phonegap hackery

Discussion in 'iOS Programming' started by 7on, Jun 27, 2011.

  1. 7on macrumors 601

    7on

    Joined:
    Nov 9, 2003
    Location:
    Dress Rosa
    #1
    Ok so we're doing an application in Phonegap and there's only one thing we need to change in the source - the capture size from the camera.

    I managed by with Android in Eclipse, but ObjC is giving me some woahs.

    Code:
    CGSize size = [image size];
    NSValue *imagewidth = [NSValue valueWithCGSize:size.width];
    NSValue *imageheight = [NSValue valueWithCGSize:size.height];
    
    NSValue *imageRatio = imagewidth / imageheight;
    
    if (imageRatio < 1 ) {
    	CGSize newSize = CGSizeMake(768,1024);
    } else {
    	CGSize newSize = CGSizeMake(1024,768);
    }
    	
    	UIGraphicsBeginImageContext( newSize );
    	[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    	image = UIGraphicsGetImageFromCurrentImageContext();
    	UIGraphicsEndImageContext();
    It worked BEFORE I tried to calculate the imageRatio and I know Xcode is telling me there's "Incompatible types in initialization" on the line 2 I just don't know what what would be the compatible type.

    Basically I'm resizing the image to 1024x768. If it's portrait use the 768x1024.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    This line is meaningless:

    Code:
    NSValue *imageRatio = imagewidth / imageheight;
    You cannot divide pointers and expect to get an object. Or a reasonable answer. This is not C++. There is no operator overloading

    Then you try and compare a point with a value on this line:

    Code:
    if (imageRatio < 1
    Again this is nonsensical.

    I cannot really see any reason for you to be using NSValue at all. It's gaining you nothing.

    Why can't you do:
    Code:
    float imageRatio = size.width/size.height;
    
    if (imageRatio < 1 ) {
    	CGSize newSize = CGSizeMake(768,1024);
    } else {
    	CGSize newSize = CGSizeMake(1024,768);
    }
    
     
  3. 7on thread starter macrumors 601

    7on

    Joined:
    Nov 9, 2003
    Location:
    Dress Rosa
    #3
    Eureka! Thanks!

    It's true, I don't have the slightest idea what I'm doing. And I'll be the first to tell anyone that I'm a designer first and anything dealing with code second.

    I had to stick the newSize declaration outside the conditional for it to work though.

    Code:
    
    CGSize size = [image size];
    CGSize newSize;
    
    float imageRatio = size.width/size.height;
    
    if (imageRatio < 1) {
    	newSize = CGSizeMake(768,1024);
    } else {
    	newSize = CGSizeMake(1024,768);
    }
    	
    UIGraphicsBeginImageContext( newSize );
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    
    I added it at line 82 of Camera.m in Phonegap0.9.4 if anyone wants to limit their photos to 1MP in that thing. Though everyone in this forum may already know how to do this, it might help a Googler down the road.
     

Share This Page