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;
Related
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!
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 loaded an array:
currentBackground=4;
bgImages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:#"mystery_01 320x460"],
[UIImage imageNamed:#"mystery_02 320x460"],
[UIImage imageNamed:#"mystery_03 320x460"],
[UIImage imageNamed:#"mystery_04 320x460"],
[UIImage imageNamed:#"mystery_05 320x460"],
nil];
Now I want to display in a label the file name of the image currently being displayed. I thought:
mainLabel.text = [NSString stringWithFormat:#"bgImages= %#",[bgImages objectAtIndex:currentBackground]];
would work but all I get is hex code . I have a button that scrolls through the images very nicely. But when I try to display the image name all I get is what I believe to be the address where the name resides.
The file name of the image is not stored in your UIImage object. There is no such property in the UIImage class. You'll have to store the names yourself. Perhaps you could store the file names in an array, and use this array both to retrieve the images from file and then to look up the image file names later:
imageFileNames = [[NSArray alloc] initWithObjects:
#"mystery_01 320x460",
#"mystery_02 320x460",
#"mystery_03 320x460",
#"mystery_04 320x460",
#"mystery_05 320x460",
nil];
Retrieve the images (you could use a for-in loop for this instead if you wish):
bgImages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:[imageFileNames objectAtIndex:0]],
[UIImage imageNamed:[imageFileNames objectAtIndex:1]],
[UIImage imageNamed:[imageFileNames objectAtIndex:2]],
[UIImage imageNamed:[imageFileNames objectAtIndex:3]],
[UIImage imageNamed:[imageFileNames objectAtIndex:4]],
nil];
Get the file name from your file names array:
mainLabel.text = [NSString stringWithFormat:#"bgImages= %#",[imageFileNames objectAtIndex:currentBackground]];
Using %# in your string format effectively just calls the object's description method. The hex value you are seeing is just the value of the object pointer - this is NSObject's default implementation of the description method.
Note that for an NSString objects, the description method returns... You guessed it - the NSString object itself.
In your case, to display the image names, you have to keep them, as it seems UIImage's description doesn't return the image name.
You can also make a UIImage subclass which remembers the name, but not sure it's worth the hassle.
I am loading files that are downloaded from the web in a UIWebView (HTML files).
Is there a way to create a UIImage from an HTML file located in the Documents folder?
The goal is to auto generate thumbnails without needing to manual create them...
Update
My train of thought would be to do something in the line of:
NSString * s = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"html"];
UIImage *image = [[UIImage alloc] initWithData:
[NSData dataWithContentsOfURL:url]];
Which of course does not work in this case!
Thanks!
S.
I found this solution here
UIGraphicsBeginImageContext(yourWebView.bounds.size);
[yourWebView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultImageView = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
resultImageView will be an image that contains the render of yourWebView.
If you want to shrink it down to a thumbnail size from there, I like Trevor's UIImage category for that purpose.
I need to access the iphone APIs to read a multipage TIFF image file format, dose anyone know how:, if not how can I build and use the open source libtiff on iphone/xcode.
I've created my own solution for this: NSTiffSplitter.
You can find it on github.
NSString *pathToImage = [[NSBundle mainBundle] pathForResource:#"Example" ofType:#"tiff"];
NSTiffSplitter* splitter = [[NSTiffSplitter alloc] initWithPathToImage:pathToImage];
UIImage *page = [[UIImage alloc] initWithData:[splitter dataForImage:page]];
yourImageView.image = page;
[page release];