Commits

Ivan Andrus  committed bfb0438

Prescale images for table view

  • Participants
  • Parent commits b79a2ed

Comments (0)

Files changed (2)

File Classes/EditViewController.m

             NSString* sub = [out substringFromIndex:NSMaxRange(r1)];
             NSRange r2 = [sub rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"\""]];
 
-            cell.image = [NSData dataFromBase64String:[sub substringToIndex:r2.location]];
+            // For some reason scaling it myself makes it look much nicer
+            UIImage * image = [UIImage imageWithData:[NSData dataFromBase64String:[sub substringToIndex:r2.location]]];
+            CGSize size = CGSizeMake(70.f, 70.0f);
+            UIGraphicsBeginImageContext(size);
+            [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
+            UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
+            UIGraphicsEndImageContext();
+            cell.image = [NSData dataWithData:UIImagePNGRepresentation(scaledImage)];
 
         }
         out = [outputView stringByEvaluatingJavaScriptFromString:@"isageGetOutputForStorage(true)"];
                                       inputView.superview.frame.size.width,
                                       inputView.superview.frame.size.height - yoffset);
     }
-
-/*
-
-    if ( !imageView.hidden ) {
-        imageView.frame = CGRectMake(imageView.frame.origin.x,
-                                     imageView.frame.origin.y,
-                                     imageView.frame.size.width,
-                                     imageView.frame.size.width * imageView.image.size.height / imageView.image.size.width);
-
-        scrollView.contentSize = CGSizeMake(imageView.frame.origin.x + imageView.frame.size.width + 5.0,
-                                            imageView.frame.origin.y + imageView.frame.size.height + 5.0 );
-
-    }
- */
 }
 
 

File Classes/RootViewController.m

     }
 
     if ( alephCell.image ) {
-        // TODO: move this to where I store the image
-        // For some reason scaling it myself first makes it look much nicer
+
+        // Images are now prescaled
         UIImage * image = [UIImage imageWithData:alephCell.image];
-        CGSize size = CGSizeMake(70.f, 70.0f);
-        UIGraphicsBeginImageContext(size);
-        [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
-        UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
-        UIGraphicsEndImageContext();
+        if ( image.size.width == 70.f ) {  // I know comparing floats is bad...
+            cell.imageView.image = image;
+        } else {
+            // This is only here for old images that weren't prescaled.
+            CGSize size = CGSizeMake(70.f, 70.0f);
+            UIGraphicsBeginImageContext(size);
+            [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
+            UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
+            UIGraphicsEndImageContext();
 
-        cell.imageView.image = scaledImage;
+            cell.imageView.image = scaledImage;
+        }
+
     } else {
         // In case it's reused from one that had an image
         // TODO: perhaps we should use a different cell cache for those with images...