Can't tweet an image - iphone

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
forTweet = TRUE;
switch(buttonIndex)
{
case 0:
{
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// Set the initial tweet text. See the framework for additional properties that can be set.
NSMutableString * twitterString = [displayString mutableCopy];
[twitterString appendString: #" #LoviOtvet"];
[tweetViewController setInitialText: twitterString];
UIImage * imageAnswer = [self getImageFromURL: [self strToUrlConverter]];
UIImage * imageLogo = [[UIImage alloc] initWithContentsOfFile: #"image.png"];
[tweetViewController addImage: [self mergeImage:imageAnswer withImage:imageLogo strength:1]];
break;
}
I added . No errors, but not working.
Facebook and saving to device working. Tweeting not. Why not?

Your problem is this line:
UIImage * imageLogo = [[UIImage alloc] initWithContentsOfFile: #"image.png"];
For this method, you would need to need to provide a file path, not a name. You have two choices:
UIImage * imageLogo = [UIImage imageNamed:]
or (for a file in the bundle):
NSString *path = [[NSBundle mainBundle] pathForResource:#"image" ofType:#"png"];
UIImage * imageLogo = [[UIImage alloc] initWithContentsOfFile:path];

Related

iphone: Three20 library's MockPhoto with server images

I am trying to download images from server and display in 320 library's TTThumbsViewController. I am not able to get this working!
Following works for me when I have images locally stored:
//Create thumbnails
[ImageUtils checkAndSaveThumbnail:imageName andSize:CGSizeMake(100.0, 100.0) andLocation:NO andPrefixof:#"small"];
NSString *fullImageName = [NSString stringWithFormat:#"documents://%#",imageName];
NSString *imageSmallName = [NSString stringWithFormat:#"documents://small-%#",imageName];
NSString *caption = [tempDict objectForKey:#"Comment"];
UIImage *tempImage = [UIImage imageWithContentsOfFile:[appDelegate filePath:imageName]];
MockPhoto *tempPicture = [[MockPhoto alloc] initWithURL:fullImageName smallURL:imageSmallName size:tempImage.size caption:caption photoname:imageName];
[photoArray addObject:tempPicture];
Adding photoArray into MockPhotoSource:
self.photoSource = [[MockPhotoSource alloc]
initWithType:MockPhotoSourceNormal
title:#"Photos"
photos:photoArray
photos2:nil
];
[photoArray release];
...But when I give download location like following it doesn't work! Doesn't show me thumbnails and neither large pics!
NSString *url = [delegate downloadImageUrl];
MockPhoto *tempPicture = [[MockPhoto alloc] initWithURL:url smallURL:url size:tempImage.size caption:caption photoname:imageName];
[photoArray addObject:tempPicture];
I have been using same same URL with AsyncImage and it downloads image and show in ImageView fine!
NSURL *url = [NSURL URLWithString:[delegate downloadImageUrl]];
UIImageView *profileimage = [[UIImageView alloc] init];
AsyncImageView* asyncImage = [[[AsyncImageView alloc] initWithFrame:CGRectMake(0, 10, 60, 60)] autorelease];
asyncImage.imageName = [[users objectAtIndex:indexPath.row] objectForKey:#"Key"];
[asyncImage loadImageFromURL:url];
[profileimage addSubview:asyncImage];
Could you please let me know what's wrong am I doing with MockPhoto?
Thanks.

OpenFlow with XML Object

Trying to use OpenFlow API for iPhone SDK.
I need the openflow to load pictures from a (image) link.
This is how it always works with local images:
loadImagesOperationQueue = [[NSOperationQueue alloc] init];
NSString *imageName;
for (int i=0; i < 10; i++) {
imageName = [[NSString alloc] initWithFormat:#"cover_%d.jpg", i];
[(AFOpenFlowView *)self.view setImage:[UIImage imageNamed:imageName] forIndex:i];
[imageName release];
NSLog(#"%d is the index",i);
}
[(AFOpenFlowView *)self.view setNumberOfImages:10];
And I tried this:
- (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex:(int)index {
NSString *photoUrl = [[oldEntries objectAtIndex: 0] objectForKey: #"still"];
NSURL *photomake = [NSURL URLWithString:photoUrl];
NSLog(#"theConnection: %#",photoUrl);
NSLog(#"theConnection: %#",photomake);
AFGetImageOperation *getImageOperation = [AFGetImageOperation alloc];
// We're getting our images from the Flickr API.
getImageOperation.imageURL = photomake;
[loadImagesOperationQueue addOperation:getImageOperation];
[(AFOpenFlowView *)self.view setNumberOfImages:1];
[getImageOperation release];
}
But it just won't work. Can anyone help me?
Without knowing what 'won't work' it's hard to say, please clarify and supply the actual URL you are creating.
The only line that looks suspect is this one:
AFGetImageOperation *getImageOperation = [AFGetImageOperation alloc];
Should be:
AFGetImageOperation *getImageOperation = [[AFGetImageOperation alloc] init];
It's much easier to use:
NSURL *imageUrl = [[NSURL alloc] initWithString:[#"path/to/the/file.jpg"];
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
UIImage *image = [UIImage imageWithData:imageData];
put all the images in an Array
and then you call you first function
for (int i=0; i < 10; i++) {
imageName = [[NSString alloc] initWithFormat:#"cover_%d.jpg", i];
[(AFOpenFlowView *)self.view setImage:**image** forIndex:i];
[imageName release];
NSLog(#"%d is the index",i);
}
[(AFOpenFlowView *)self.view setNumberOfImages:10];

Retrieving the UIImage of a TTPhotoViewController

I have a TTPhotoViewController subclass working nicely. I need to be able to give the option of saving the image downloaded to the user's saved photos directory. I am having problems actually retrieving a UIImage object.
After looking through the API I have seen that TTPhoto (which is one of the properties of the view controller) doesn't actually contain a UIImage to use. However, within the API there is a TTImageView class which has a UIImage property. TTPhotoView derives from TTImageView and there is one of these in my view controller class called "PhotoStatusView". However when I access this I do not get a UIImage back.
Any ideas?
Check this site out add save to album functionality
Here is the code from the site:
_clickActionItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemAction
//TTIMAGE(#"UIBarButtonReply.png")
target:self action:#selector(clickActionItem)];
UIBarButtonItem* playButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemPlay target:self action:#selector(playAction)] autorelease];
playButton.tag = 1;
UIBarItem* space = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
_toolbar = [[UIToolbar alloc] initWithFrame:
CGRectMake(0, screenFrame.size.height - TT_ROW_HEIGHT,
screenFrame.size.width, TT_ROW_HEIGHT)];
_toolbar.barStyle = self.navigationBarStyle;
_toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleTopMargin;
NSString *searchCaption = #"Photo from networked";
NSRange range = [[_centerPhoto caption] rangeOfString:searchCaption];
if (range.location == NSNotFound) {
_toolbar.items = [NSArray arrayWithObjects:
space, _previousButton, space, _nextButton, space,_clickActionItem, nil];
[_innerView addSubview:_toolbar];
}else{
_toolbar.items = [NSArray arrayWithObjects:
space, _previousButton, space, _nextButton, space, nil, nil];
[_innerView addSubview:_toolbar];
}
and this
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(6 == actionSheet.tag)
{
if(0 == buttonIndex)//save page
{
NSLog(#"photo: %#", [_centerPhoto URLForVersion:TTPhotoVersionLarge]);
NSURL *aUrl = [NSURL URLWithString:[_centerPhoto URLForVersion:TTPhotoVersionLarge]];
NSData *data = [NSData dataWithContentsOfURL:aUrl];
UIImage *img = [[UIImage alloc] initWithData:data];
NSLog(#"photo:class %#", [img class]);
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
You should try using:
UIImage *image = [[TTURLCache sharedCache] imageForURL:URL];

Xcode iPhone Programming: Loading a jpg into a UIImageView from URL

My app has to load an image from a http server and displaying it into an UIImageView
How can i do that??
I tried this:
NSString *temp = [NSString alloc];
[temp stringwithString:#"http://192.168.1.2x0/pic/LC.jpg"]
temp=[(NSString *)CFURLCreateStringByAddingPercentEscapes(
nil,
(CFStringRef)temp,
NULL,
NULL,
kCFStringEncodingUTF8)
autorelease];
NSData *dato = [NSData alloc];
dato=[NSData dataWithContentsOfURL:[NSURL URLWithString:temp]];
pic = [pic initWithImage:[UIImage imageWithData:dato]];
This code is in viewdidload of the view but nothing is displayed!
The server is working because i can load xml files from it. but i can't display that image!
I need to load the image programmatically because it has to change depending on the parameter passed!
Thank you in advance.
Antonio
It should be:
NSURL * imageURL = [NSURL URLWithString:#"http://192.168.1.2x0/pic/LC.jpg"];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * image = [UIImage imageWithData:imageData];
Once you have the image variable, you can throw it into a UIImageView via it's image property, ie:
myImageView.image = image;
//OR
[myImageView setImage:image];
If you need to escape special characters in your original string, you can do:
NSString * urlString = [#"http://192.168.1.2x0/pic/LC.jpg" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL * imageURL = [NSURL URLWithString:urlString];
....
If you're creating your UIImageView programmatically, you do:
UIImageView * myImageView = [[UIImageView alloc] initWithImage:image];
[someOtherView addSubview:myImageView];
[myImageView release];
And because loading image from URL takes ages, it would be better to load it asynchronously. The following guide made it stupid-simple for me:
http://www.switchonthecode.com/tutorials/loading-images-asynchronously-on-iphone-using-nsinvocationoperation
Try this
NSURL *url = [NSURL URLWithString:#"http://192.168.1.2x0/pic/LC.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImageView *subview = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,320.0f, 460.0f)];
[subview setImage:[UIImage imageWithData:data]];
[cell addSubview:subview];
[subview release];
All the Best.
This is the actual code.
UIImageView *myview=[[UIImageView alloc]init];
myview.frame = CGRectMake(0, 0, 320, 480);
NSURL *imgURL=[[NSURL alloc]initWithString:#"http://soccerlens.com/files/2011/03/chelsea-1112-home.png"];
NSData *imgdata=[[NSData alloc]initWithContentsOfURL:imgURL];
UIImage *image=[[UIImage alloc]initWithData:imgdata];
myview.image=image;
[self.view addSubview:myview];
You should load the image in the background or the view will freeze.
Try this:
UIImage *img = [[UIImage alloc] init];
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:#"http://www.test.com/test.png"];
img = [UIImage imageWithData: data];
dispatch_async(dispatch_get_main_queue(), ^{
//PUT THE img INTO THE UIImageView (imgView for example)
imgView.image = img;
});
});

setting the images in a tableview which i am getting from the server?

I am using the code below to set images in a table which are loaded from the server, but I have an exception thrown (not every time) which is related to a drawing error
- (void) getTheThumnbails:(NSIndexPath *)indexPath{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
GDataEntryYouTubeVideo *entry = [feedArray objectAtIndex:indexPath.row];
NSURL *url = [[NSURL alloc] initWithString:[[[[entry mediaGroup] mediaThumbnails] objectAtIndex:0] URLString]];
NSData *imgData = [[NSData alloc] initWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:imgData];
CGRect newFrame = CGRectMake(0.0, 0.0, 62.0, 62.0);
UIGraphicsBeginImageContext(newFrame.size);
[img drawInRect:newFrame];
UIImage *resizedImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[imgDict setObject:resizedImg forKey:[NSString stringWithFormat:#"%i",indexPath.row]];
[[[myTableView cellForRowAtIndexPath:indexPath] imageView] setImage:resizedImg];
[pool release];
}
Please help me folks, sorting out the mistake i am doing.
Trying to draw a image in a thread is not a good practice, please do not perform any UI operations in thread, they need to be done in the main thread.
well I did the above like
- (void) getTheThumnbails:(NSIndexPath *)indexPath{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
GDataEntryYouTubeVideo *entry = [feedArray objectAtIndex:indexPath.row];
NSURL *url = [[NSURL alloc] initWithString:[[[[entry mediaGroup] mediaThumbnails] objectAtIndex:0] URLString]];
NSData *imgData = [[NSData alloc] initWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:imgData];
[imgDict setObject:img forKey:[NSString stringWithFormat:#"%i",indexPath.row]];
[img release];
[self performSelectorOnMainThread:#selector(setImageInTable:) withObject:indexPath waitUntilDone:NO];
[pool release];
}
- (void)setImageInTable:(NSIndexPath *)indexPath{
UIImage *img = (UIImage *)[imgDict valueForKey:[NSString stringWithFormat:#"%i",indexPath.row]];
CGRect newFrame = CGRectMake(0.0, 0.0, 62.0, 62.0);
UIGraphicsBeginImageContext(newFrame.size);
[img drawInRect:newFrame];
UIImage *resizedImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[imgDict removeObjectForKey:[NSString stringWithFormat:#"%i",indexPath.row]];
[imgDict setObject:resizedImg forKey:[NSString stringWithFormat:#"%i",indexPath.row]];
[[[myTableView cellForRowAtIndexPath:indexPath] imageView] setImage:resizedImg];
}
Hope this helps.
Thanks,
Madhup