检查UIImageView的图像是否已更改

发布于 2024-10-04 08:39:16 字数 353 浏览 0 评论 0原文

好的,所以我有一个问题,我需要检查用户是否更改了内部图像和 imageView。如果不是,那么应用程序不需要重新保存一堆东西,并且它被更改,那么它应该保存。所以基本上这只是为了优化代码,因为在保存时我将四个图像(loRes、loResThumb、hiRes 和 hiResthumb)写入磁盘,这需要一些时间。

我想我可以尝试通过在用户进入编辑模式时将图像保存为 NSDATA 来实现这一点,然后当用户退出时,检查并查看 UIIMageView 中包含的 NSDATA 是否与我之前临时保存的相同。这会起作用还是它们是更好的方法,例如检查 UIImagePicker 是否已被调用(并不一定意味着图像已更改,但至少比每次保存更接近)。

任何提示表示赞赏。谢谢!

Ok, so I have a problem where I need to check if the user has changed the image inside and imageView. If no then the app doesn't need to resave a bunch of stuff and it is changed then it should save. So bascically this is just to optimize the code since when saving I am writing four images (loRes, loResThumb, hiRes and hiResthumb) to disk and that takes a little while.

I thought I might try doing it by saving the image as NSDATA when the user enters edit mode and then when the users exits, check and see if the NSDATA contained in the UIIMageView is the same as the one I saved temporarily before. Would that work or is their a better way, like checking if the UIImagePicker has been called (doesn't necessarily mean the image is changed but at least it closer than just saving every time).

Any tips appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶…霜飞 2024-10-11 08:39:16

尝试创建 UIImageView 的子类,如果设置了 image,则“标记”脏值。

@interface myImageView : UIImageView {
    BOOL _dirty; // set to NO in init
}

- (BOOL) hasChanged;

@end

@implementation


- (void) setImage: (UIImage *)image
{
    [super setImage:image];
    _dirty = YES;
}

- (BOOL) hasChanged
{
   if (!_dirty) return NO;
   _dirty = NO;
   return YES;
}
@end

Try creating a subclass of UIImageView that 'tags' a dirty value if image is set.

@interface myImageView : UIImageView {
    BOOL _dirty; // set to NO in init
}

- (BOOL) hasChanged;

@end

@implementation


- (void) setImage: (UIImage *)image
{
    [super setImage:image];
    _dirty = YES;
}

- (BOOL) hasChanged
{
   if (!_dirty) return NO;
   _dirty = NO;
   return YES;
}
@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文