I have a UIImageView
that diaplays an image. Then I have a button titled 'save' . What I want to do is that when I click the button, it should save the image file name into a plist
for further retrieval and stuff.
我有一个用于显示图像的UIImageView。然后我有一个标题为“保存”的按钮。我想要做的是,当我点击按钮时,它应该将图像文件名保存到plist中以便进一步检索和填充。
I know how to save into plist
and all. The problem is only that I don't know how to get the file path of the image being displayed in the UIImageView
.
我知道如何保存到plist和所有。问题只是我不知道如何获取UIImageView中显示的图像的文件路径。
I did homework and found few articles but im still confused. Any help will be appreciated.
我做了功课,发现了一些文章,但我仍然感到困惑。任何帮助将不胜感激。
3 个解决方案
#1
1
I dont think it is possible to get the image path from a UIImage, if by path you mean the original location on disk, then i dont think that you can do it
我不认为有可能从UIImage获取图像路径,如果通过路径你的意思是磁盘上的原始位置,那么我不认为你可以做到这一点
#2
0
The best way to do this is to Save the image in document folder with name image1, image2, etc or the exact name of the image if you know it. And you can save the image names in the plist. Using the names here you can do the further stuff easily.
执行此操作的最佳方法是将图像保存在文档文件夹中,其名称为image1,image2等,或者如果您知道图像的确切名称。您可以将图像名称保存在plist中。使用此处的名称,您可以轻松完成更多工作。
#3
0
Create UIImageview
as CustomImageview
class with NSString
variable.Then while showing that image,store the image file path in that string variable.Then you can get it where ever you want with the use of that string.Use the following code
使用NSString变量将UIImageview创建为CustomImageview类。然后在显示该图像时,将图像文件路径存储在该字符串变量中。然后,您可以使用该字符串获取所需的位置。使用以下代码
#import <UIKit/UIKit.h>
@interface Imager : UIImageView
{
NSString* imageFileName; @property(nonatomic,retain)NSString* imageFileName;
}
@end
#import "Imager.h"
@implementation
@synthesize imageFileName
and the assign the filepathname where you are assigning the image like your Imageview.image = UIImage;
your Imageview.imageFileName=yourImageFilepath;
并指定文件路径名,在其中分配图像,如Imageview.image = UIImage;你的Imageview.imageFileName = yourImageFilepath;
to get the yourImageFilepath add "AssetsLibrary.framework" to your framework folder.Then add #import "AssetsLibrary/AssetsLibrary.h"; to the header file of your class.
获取yourImageFilepath将“AssetsLibrary.framework”添加到您的框架文件夹中。然后添加#import“AssetsLibrary / AssetsLibrary.h”;到你班级的头文件。
then add the following code in "didFinishPickingMediaWithInfo" method
然后在“didFinishPickingMediaWithInfo”方法中添加以下代码
UIImage *viewImage = yourImage;
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation: (ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error)
{
if (error)
{
NSLog(@"error");
}
else
{
NSLog(@"url %@", assetURL);
}
}];
[library release];
It will return a url.that is your yourImageFilepath.
它将返回一个url.that是你的yourImageFilepath。
#1
1
I dont think it is possible to get the image path from a UIImage, if by path you mean the original location on disk, then i dont think that you can do it
我不认为有可能从UIImage获取图像路径,如果通过路径你的意思是磁盘上的原始位置,那么我不认为你可以做到这一点
#2
0
The best way to do this is to Save the image in document folder with name image1, image2, etc or the exact name of the image if you know it. And you can save the image names in the plist. Using the names here you can do the further stuff easily.
执行此操作的最佳方法是将图像保存在文档文件夹中,其名称为image1,image2等,或者如果您知道图像的确切名称。您可以将图像名称保存在plist中。使用此处的名称,您可以轻松完成更多工作。
#3
0
Create UIImageview
as CustomImageview
class with NSString
variable.Then while showing that image,store the image file path in that string variable.Then you can get it where ever you want with the use of that string.Use the following code
使用NSString变量将UIImageview创建为CustomImageview类。然后在显示该图像时,将图像文件路径存储在该字符串变量中。然后,您可以使用该字符串获取所需的位置。使用以下代码
#import <UIKit/UIKit.h>
@interface Imager : UIImageView
{
NSString* imageFileName; @property(nonatomic,retain)NSString* imageFileName;
}
@end
#import "Imager.h"
@implementation
@synthesize imageFileName
and the assign the filepathname where you are assigning the image like your Imageview.image = UIImage;
your Imageview.imageFileName=yourImageFilepath;
并指定文件路径名,在其中分配图像,如Imageview.image = UIImage;你的Imageview.imageFileName = yourImageFilepath;
to get the yourImageFilepath add "AssetsLibrary.framework" to your framework folder.Then add #import "AssetsLibrary/AssetsLibrary.h"; to the header file of your class.
获取yourImageFilepath将“AssetsLibrary.framework”添加到您的框架文件夹中。然后添加#import“AssetsLibrary / AssetsLibrary.h”;到你班级的头文件。
then add the following code in "didFinishPickingMediaWithInfo" method
然后在“didFinishPickingMediaWithInfo”方法中添加以下代码
UIImage *viewImage = yourImage;
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation: (ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error)
{
if (error)
{
NSLog(@"error");
}
else
{
NSLog(@"url %@", assetURL);
}
}];
[library release];
It will return a url.that is your yourImageFilepath.
它将返回一个url.that是你的yourImageFilepath。