2012-04-23 3 views
0

UIImage를 jpeg 또는 png와 같은 형식으로 변환하여 "AddThis"라는 IOS 플러그인을 사용하여 해당 파일을 공유 할 수 있습니다. ".AddThis 플러그인을 사용하여 UIImage를 jpeg/png 파일로 변환

[AddThisSDK shareImage:[UIImage imageNamed:@"test.jpg] withService:@"twitter" title:@"I'm sharing something" description:@"Random description of image"]; 

: 나는 그 다음, 내가 먼저 JPEG에있는 UIImage을 변환 할 수있는 방법을 찾을 필요가 그것을 지원이 코드에 추가하지 않습니다 만있는 UIImage하지만 플러그인을 사용하여 공유하려고 코드에 shareImage:[UIImageNamed:@""]이 있어야합니다. 그렇지 않으면 오류가 발생합니다.

지금까지 UIImageJPEGRepresentation을 사용하여 변환하려고 시도했지만 올바르게 작성했다고 생각하지 않습니다. 바로 이미지를 복용 당신이 그것을 변환하는 것입니다 방법과 유사하게 그것을 시도 솔직히 말해서 :

NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"photo_boom.jpg"]; 

[UIImageJPEGRepresentation(shareImage, 1.0) writeToFile:jpgPath atomically:YES]; 

NSError *error; 
NSFileManager *fileMgr = [NSFileManager defaultManager]; 

NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"photo_boom.jpg"]; 

NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]); 

뭔가 날이 내가 수 없어 주로하기 때문에 ... 올바른 방법으로하지 않습니다 말한다 그것을 작동 시키려면.

정말 도움을 주실 수 있습니다.

기본적으로, 나는 UIView의 변환에서있는 UIImage했습니다 : 나는 다음 JPEG 형식을 제공 할

UIGraphicsBeginImageContext(firstPage.bounds.size); 
[firstPage.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 

을하기 때문에 단순히

[AddThisSDK shareImage:image withService:@"twitter" title:@"I'm sharing something" description:@"Random description of image"]; 

로 넣어하려고 할 때 그것은 나에게 오류가 발생합니다

답변

1

이미지 자체 내부 표현을 가지고 있으므로 jpeg 또는 png 데이터로로드하는지 여부와 관계가 없습니다.

API를

는 제공 photo_boom.jpg이 번들에 포함되어 작동합니다

[AddThisSDK shareImage:[UIImage imageNamed:@"photo_boom.jpg"] 
      withService:@"twitter" 
       title:@"I'm sharing something" 
      description:@"Random description of image"]; 

의 라인을 따라 첫 번째 매개 변수로 UIImage, 그래서 무언가가 관심을 호출합니다. 그래도 문제가 해결되지 않으면, 당신은 AddThisSDK 줄에 중단 점을 넣고, 값을 확인하는 시도가

NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"photo_boom.jpg"]; 
UIImage * myImage = [UIImage imageWithContentsOfFile: jpgPath]; 

[AddThisSDK shareImage:myImage 
      withService:@"twitter" 
       title:@"I'm sharing something" 
      description:@"Random description of image"]; 

: 당신이 폴더에서 이전에 저장 한 이미지를로드하는 경우, 당신은 이런 식으로 뭔가를해야합니다 image? 콘솔에 po image을 입력하십시오.

+0

작동하지 않았지만 photo_boom.jpg가 기존 파일이 아니기 때문에 발생했습니다. 기본적으로 UIView 변환 UIImage 만들었습니다 : 'UIGraphicsBeginImageContext (firstPage.bounds.size); [firstPage.layer renderInContext : UIGraphicsGetCurrentContext()]; 있는 UIImage * 이미지 = UIGraphicsGetImageFromCurrentImageContext(); '그때 나는 단순히'[AddThisSDK shareImage로 넣어하려고 할 때 때문에 JPEG 형식을 제공 할 : 이미지 withService : @ 제목을 "트위터"나는' "@ " 설명 : @"이미지의 무작위 설명 "]; ' 오류가 발생합니다 – Ollie177

+0

jpeg 형식의 UIImage 같은 것은 존재하지 않습니다. 자체 포맷을 가지고 있습니다. 어떤 오류가 발생하고 있습니까? –

+0

코드 안에 없기 때문에 플러그인 자체와 함께 있습니다. 내 앱을 테스트 할 때입니다. 단지 "오류가 발생했습니다"라고 말합니다. 나는 플러그인이'[AddThisSDK shareImage : [UIImage imageNamed : @ "photo_boom.[AddThisSDK shareImage : image' – Ollie177