Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using MonoTouch.Dialog;
- using MonoTouch.Foundation;
- using MonoTouch.UIKit;
- using System.Drawing;
- namespace MenuFinderMT
- {
- //cell.ImageView.ContentMode = UIViewContentMode.Center;
- public class JMAImageElement : Element, IElementSizing
- {
- static NSString skey = new NSString ("About_Image");
- UIImage image;
- float limit = 600;
- DialogViewController dvc;
- public JMAImageElement (string caption, byte[] bytes, DialogViewController dvc)
- : base(string.Empty)
- {
- this.dvc = dvc;
- SizeF sz = new SizeF (600, 600);
- //320 x 480 old iPhone support
- if(dvc.View.Frame.Width < 600)
- {
- limit = (float)dvc.View.Frame.Width - 200;
- sz = new SizeF(300, 300);
- }
- this.image = Scale (GetImagefromByteArray(bytes), sz);
- }
- public override UITableViewCell GetCell (UITableView tv)
- {
- var cell = tv.DequeueReusableCell (skey);
- if (cell == null) {
- cell = new UITableViewCell (UITableViewCellStyle.Default, skey)
- {
- SelectionStyle = UITableViewCellSelectionStyle.None,
- Accessory = UITableViewCellAccessory.None,
- };
- }
- if (null != image) {
- cell.ImageView.Image = image;
- cell.ImageView.ContentMode = UIViewContentMode.Center;
- }
- return cell;
- }
- public float GetHeight (UITableView tableView, NSIndexPath indexPath)
- {
- float height = 100;
- if (null != image)
- height = image.Size.Height;
- return height;
- }
- UIImage GetImagefromByteArray (byte[] imageBuffer)
- {
- NSData imageData = NSData.FromArray (imageBuffer);
- return UIImage.LoadFromData (imageData);
- }
- UIImage Scale (UIImage source, SizeF newSize)
- {
- if ((dvc.View.Frame.Size.Width > limit) || (dvc.View.Frame.Size.Height > limit)) {
- 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;
- } else {
- return source;
- }
- }
- public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath indexPath)
- {
- //base.Selected(dvc, tableView, path);
- tableView.DeselectRow (indexPath, true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment