NSImage+WebCache.m 1013 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "NSImage+WebCache.h"
  9. #if SD_MAC
  10. @implementation NSImage (WebCache)
  11. - (CGImageRef)CGImage {
  12. NSRect imageRect = NSMakeRect(0, 0, self.size.width, self.size.height);
  13. CGImageRef cgImage = [self CGImageForProposedRect:&imageRect context:NULL hints:nil];
  14. return cgImage;
  15. }
  16. - (NSArray<NSImage *> *)images {
  17. return nil;
  18. }
  19. - (BOOL)isGIF {
  20. BOOL isGIF = NO;
  21. for (NSImageRep *rep in self.representations) {
  22. if ([rep isKindOfClass:[NSBitmapImageRep class]]) {
  23. NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep;
  24. NSUInteger frameCount = [[bitmapRep valueForProperty:NSImageFrameCount] unsignedIntegerValue];
  25. isGIF = frameCount > 1 ? YES : NO;
  26. break;
  27. }
  28. }
  29. return isGIF;
  30. }
  31. @end
  32. #endif