I'm using SMTP framework to send an email with an video. The code for send images and text is:
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:#"text/plain",kSKPSMTPPartContentTypeKey,
#"Some text to include in body",kSKPSMTPPartMessageKey,#"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
UIImage* image = [UIImage imageNamed:#"picture1"];
NSData *vcfData = UIImageJPEGRepresentation(image, 50);
NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:#"image/jpg;\r\n\tx-unix-mode=0644;\r\n\tname=\"image.jpg\"",kSKPSMTPPartContentTypeKey,
#"attachment;\r\n\tfilename=\"image.jpg\"",kSKPSMTPPartContentDispositionKey,[vcfData encodeBase64ForData],kSKPSMTPPartMessageKey,#"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
And then add the part(image) to NSArray parts to send this.
testMsg.parts = [NSArray arrayWithObjects:plainPart,vcfPart,nil];
But I don't know how can I add a video. For an image is UIImage, but for video?
How can I add a Video to this?
Thanks!
Related
i have one NSMutableArray with some image url's. The images have sizes between 12KB to 6MB. I use AsycImageView class and implement but when large images are downloading application get crashed, I gave 6*1024*1024 (6MB) for maxsize in that class, increase time interval 60.0 sec to 180.o sec, but there is no use. I'm getting an error "Received memory warning" and when app crash automatically connection remove from device, but in simulator there is no crash.
Use GCD for lazy loading.
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSString *strURL = url here;
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
UIImage *image = nil;
if(data)
image = [UIImage imageWithData:data];
dispatch_sync(dispatch_get_main_queue(), ^{
//now use image in image View or anywhere according to your requirement.
if(image)
yourImgView = image
});
});
you can do this using multiThreading. Here is a code
- (UIImageView *)getImageFromURL:(NSDictionary *)dict
{
#ifdef DEBUG
NSLog(#"dict:%#", dict);
#endif
UIImageView *_cellImage = nil;
_cellImage = ((UIImageView *)[dict objectForKey:#"image"]);
NSString *strURL = [dict objectForKey:#"imageurl"]);
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
#ifdef DEBUG
NSLog(#"%i", data.length);
#endif
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataFilePath = [NSString stringWithFormat:#"%#.png", [documentsDirectory stringByAppendingPathComponent:[dict objectForKey:#"imageid"]]];
if (data) // i.e. file exist on the server
{
[data writeToFile:dataFilePath atomically:YES];
_cellImage.image = [UIImage imageWithContentsOfFile:dataFilePath];
}
else // otherwise show a default image.
{
_cellImage.image = [UIImage imageNamed:#"nouser.jpg"];
}
return _cellImage;
}
And call this method in cellForRowAtIndexPath like this:
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:imageURL, #"imageurl", self.imgPhoto, #"image", imageid, #"imageid", nil];
[NSThread detachNewThreadSelector:#selector(getImageFromURL:) toTarget:self withObject:dict];
The code will start getting images in multiple threads and will save image locally to document folder. Also the image will not download again if already exists with the same name. Hope this helps
You could download image asynchronously using GCD. Use the following code,
__block NSData *imageData;
dispatch_queue_t myQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, NULL);
dispatch_async(myQueue, ^{
//load url image into NSData
imageData = [NSData dataWithContentsOfURL: your_image_URL];
if(imageData) {
dispatch_sync(dispatch_get_main_queue(), ^{
//convert data into image after completion
UIImage *img = [UIImage imageWithData:imageData];
//do what you want to do with your image
});
} else {
NSLog(#"image not found at %#", your_image_URL);
}
});
dispatch_release(myQueue);
For further info, see dispatch_queue_t
I would recommend a drop in replacement API SDWebImage it provides a category for UIImageVIew with support for remote images coming from the web. you can also have a placeholder image till the images are downloaded Asynchronously
. Its easy to use and saves a lot of work
You're problem seems to be more of a memory usage issue than it is a performance issue.
If you really want to download image asynchronously I would recommend you use The UIImageView category from AFNetworking which has been fully tested and is very well maintained.
However here you run into memory warnings on your device (which obviously holds much less memory than your simulator which runs on your Mac).
So I would use first the static analyzer:
to see if leaks are present and then run a Leaks Instrument to track it down.
Hope this helps.
I am using UIPasteboard to access copied images.
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
NSArray *images = pasteBoard.images;
It is running fine on iOS 5 devices, the array contains UIImage objects.
On device running iOS 6 the array contains NSData objects instead. Is it known issue?
Yes, after seeing your question I checked that and wondered that pasteBoard.images is returning the NSData array instead of images. So to get those images from data I used the below code and successfully got them:
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
NSArray *images = pasteBoard.images;
NSData *data = [images objectAtIndex:0];
UIImage *image = [[UIImage alloc]initWithData:data];
imageView.image = image;
If you copied more than one image then you would have to use a loop for getting all. So I think it should not be an issue.
I have an image and I want to export it to Instagram, so I can post it.
The code I'm using is:
NSURL *instagramURL = [NSURL URLWithString:#"instagram://location?id=1"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:#"Image.igo"];
UIImage *image = [UIImage imageNamed:#"01.png"];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
NSURL *imageUrl = [NSURL fileURLWithPath:savedImagePath];
NSLog(#"%#",imageUrl);
UIDocumentInteractionController *docController = [[UIDocumentInteractionController alloc] init];
docController.delegate = self;
docController.UTI = #"com.instagram.exclusivegram";
docController.URL = imageUrl;
//[docController setURL:imageUrl];
[docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
When I run the app, the App shows the button written "Instagram" its icon, but when I touch it, the button disappear, and nothing happens. The app didn't crash, but nothing happen.
What I missed in my code ?
Regards
Bruno
I guess the problem is you do not retain the UIDocumentInteractionController. Make an ivar for it in your class.
Make sure the method documentInteractionController:didEndSendingToApplication: is called on the delegate.
Also check out the Instagram documentation: http://instagram.com/developer/iphone-hooks/
When triggered, Instagram will immediately present the user with our
filter screen. The image is preloaded and sized appropriately for
Instagram. Other than using the appropriate image format, described
above, our only requirement is that the image is at least 612px tall
and/or wide. For best results, Instagram prefers opening a JPEG that
is 612px by 612px square. If the image is larger, it will be resized
dynamically.
To verify that Instagram is installed check for the URL instagram://app. The URL instagram://location?id=LOCATION_ID is intended for location feeds only!
What I am trying to do is to get image from that url
www.floraphotographs.com/showrandomiphonestuff.php?color=red&session=5345
The site displays a random image everytime , I need to be able to get the image in a NSImage object and display on the screen
Grab the data like so:
NSURL * url = [NSURL URLWithString:#"http://www.flora...."];
NSData * data = [NSData dataWithContentsOfURL:url];
Then stick it in a UIImage:
UIImage * image = [UIImage imageWithData:data];
Then put it in a UIImageView:
imageView.image = image;
I am developing mac desktop app using objective c. i have array of images to display one after one when button pressed, so i am want to use plist to store image names and i want to display image on image view using plist.
Just load your plist where you stored you image's paths to an array like this :
NSString *myfile = [[NSBundle mainBundle]
pathForResource:#"images" ofType:#"plist"];
imagesArray = [[NSArray alloc] initWithContentsOfFile:myfile];
and then when you want to display an image, juste get it's path from the array above, example :
UIImage *img = [UIImage imageNamed: [imagesArray objectAtIndex:4]];
myImageView.image = img;