Skip to content

Commit

Permalink
Merge pull request #3774 from mstepanov/timob-12189-30x
Browse files Browse the repository at this point in the history
(3_0_X)[TIMOB-12189] iOS: imageWithRoundedCorner() makes opaque corners instead of transparent corners
  • Loading branch information
vishalduggal committed Jan 24, 2013
2 parents 5f12d72 + 45bca82 commit 9580257
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions iphone/Classes/TiBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
//NOTE:FilesystemFile is conditionally compiled based on the filesystem module.
#import "TiFilesystemFileProxy.h"

static NSString *const MIMETYPE_PNG = @"image/png";
static NSString *const MIMETYPE_JPEG = @"image/jpeg";

@implementation TiBlob

-(void)dealloc
Expand Down Expand Up @@ -106,7 +109,7 @@ -(id)initWithImage:(UIImage*)image_
{
image = [image_ retain];
type = TiBlobTypeImage;
mimetype = [@"image/jpeg" retain];
mimetype = [([UIImageAlpha hasAlpha:image_] ? MIMETYPE_PNG : MIMETYPE_JPEG) copy];
}
return self;
}
Expand All @@ -117,7 +120,7 @@ -(id)initWithData:(NSData*)data_ mimetype:(NSString*)mimetype_
{
data = [data_ retain];
type = TiBlobTypeData;
mimetype = [mimetype_ retain];
mimetype = [mimetype_ copy];
}
return self;
}
Expand All @@ -128,7 +131,7 @@ -(id)initWithFile:(NSString*)path_
{
type = TiBlobTypeFile;
path = [path_ retain];
mimetype = [[Mimetypes mimeTypeForExtension:path] retain];
mimetype = [[Mimetypes mimeTypeForExtension:path] copy];
}
return self;
}
Expand Down Expand Up @@ -175,7 +178,7 @@ -(NSData*)data
}
case TiBlobTypeImage:
{
if ([@"image/png" isEqualToString:mimetype]) {
if ([mimetype isEqualToString:MIMETYPE_PNG]) {
return UIImagePNGRepresentation(image);
}
return UIImageJPEGRepresentation(image,1.0);
Expand Down Expand Up @@ -217,7 +220,7 @@ -(void)setImage:(UIImage *)image_
{
RELEASE_TO_NIL(image);
image = [image_ retain];
[self setMimeType:@"image/jpeg" type:TiBlobTypeImage];
[self setMimeType:([UIImageAlpha hasAlpha:image_] ? MIMETYPE_PNG : MIMETYPE_JPEG) type:TiBlobTypeImage];
}

-(NSString*)path
Expand Down Expand Up @@ -263,7 +266,7 @@ -(NSNumber*)length
-(void)setMimeType:(NSString*)mime type:(TiBlobType)type_
{
RELEASE_TO_NIL(mimetype);
mimetype = [mime retain];
mimetype = [mime copy];
type = type_;
}

Expand Down Expand Up @@ -302,7 +305,8 @@ - (id)imageWithAlpha:(id)args
[self ensureImageLoaded];
if (image!=nil)
{
return [[[TiBlob alloc] initWithImage:[UIImageAlpha imageWithAlpha:image]] autorelease];
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageAlpha imageWithAlpha:image]];
return [blob autorelease];
}
return nil;
}
Expand All @@ -314,7 +318,8 @@ - (id)imageWithTransparentBorder:(id)args
{
ENSURE_SINGLE_ARG(args,NSObject);
NSUInteger size = [TiUtils intValue:args];
return [[[TiBlob alloc] initWithImage:[UIImageAlpha transparentBorderImage:size image:image]] autorelease];
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageAlpha transparentBorderImage:size image:image]];
return [blob autorelease];
}
return nil;
}
Expand All @@ -326,7 +331,8 @@ - (id)imageWithRoundedCorner:(id)args
{
NSUInteger cornerSize = [TiUtils intValue:[args objectAtIndex:0]];
NSUInteger borderSize = [args count] > 1 ? [TiUtils intValue:[args objectAtIndex:1]] : 1;
return [[[TiBlob alloc] initWithImage:[UIImageRoundedCorner roundedCornerImage:cornerSize borderSize:borderSize image:image]] autorelease];
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageRoundedCorner roundedCornerImage:cornerSize borderSize:borderSize image:image]];
return [blob autorelease];
}
return nil;
}
Expand All @@ -339,12 +345,12 @@ - (id)imageAsThumbnail:(id)args
NSUInteger size = [TiUtils intValue:[args objectAtIndex:0]];
NSUInteger borderSize = [args count] > 1 ? [TiUtils intValue:[args objectAtIndex:1]] : 1;
NSUInteger cornerRadius = [args count] > 2 ? [TiUtils intValue:[args objectAtIndex:2]] : 0;
return [[[TiBlob alloc] initWithImage:[UIImageResize thumbnailImage:size
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageResize thumbnailImage:size
transparentBorder:borderSize
cornerRadius:cornerRadius
interpolationQuality:kCGInterpolationHigh
image:image]]
autorelease];
image:image]];
return [blob autorelease];
}
return nil;
}
Expand All @@ -357,7 +363,8 @@ - (id)imageAsResized:(id)args
ENSURE_ARG_COUNT(args,2);
NSUInteger width = [TiUtils intValue:[args objectAtIndex:0]];
NSUInteger height = [TiUtils intValue:[args objectAtIndex:1]];
return [[[TiBlob alloc] initWithImage:[UIImageResize resizedImage:CGSizeMake(width, height) interpolationQuality:kCGInterpolationHigh image:image hires:NO]] autorelease];
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageResize resizedImage:CGSizeMake(width, height) interpolationQuality:kCGInterpolationHigh image:image hires:NO]];
return [blob autorelease];
}
return nil;
}
Expand All @@ -374,7 +381,8 @@ - (id)imageAsCropped:(id)args
bounds.size.height = [TiUtils floatValue:@"height" properties:args def:imageSize.height];
bounds.origin.x = [TiUtils floatValue:@"x" properties:args def:(imageSize.width - bounds.size.width) / 2.0];
bounds.origin.y = [TiUtils floatValue:@"y" properties:args def:(imageSize.height - bounds.size.height) / 2.0];
return [[[TiBlob alloc] initWithImage:[UIImageResize croppedImage:bounds image:image]] autorelease];
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageResize croppedImage:bounds image:image]];
return [blob autorelease];
}
return nil;
}
Expand Down

0 comments on commit 9580257

Please sign in to comment.