Reputation: 297
Problem:
I have used following code for scaling image and make it fit to bounds of UITableviewCell in monotouch.This code is scaling image but it is making image color faint means it is not maintaining color combination.So please provide any better solution.
Code:
public static UIImage Scale (UIImage source, SizeF newSize) { UIGraphics.BeginImageContext (newSize); var context = UIGraphics.GetCurrentContext (); context.TranslateCTM (0, newSize.Height); context.ScaleCTM (1f, -1f);
context.DrawImage (new RectangleF (0, 0, newSize.Width, newSize.Height), source.CGImage);
var scaledImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return scaledImage;
}
Upvotes: 0
Views: 178
Reputation: 2572
If you want scale UIImage
, then see this method. It works fine. You should cache method's result in file system to avoid image scaling on every GetCell
.
If you source images are the same or almost the same size like UIImageView
s in UITableViewCell
Mohib Sheth solution with setting ContentMode
property is best. It source image have much greater size than UIImageView
s in UITableViewCell
, scrolling speed will be lower.
Upvotes: 1
Reputation: 1135
Read all about ContentMode for UIView in iOS here
For your requirement you would need to set the ContentMode property to UIViewContentModeScaleAspectFit
I cant help you with a sample code, since you haven't provided any code on how you are creating & populating the TableView.
Upvotes: 0