Exemplo n.º 1
0
		async Task<UIImage> GenerateDocumentThumbnailAsync (IDocument s, Praeclarum.Graphics.SizeF size, Theme theme)
		{
			var scale = UIScreen.MainScreen.Scale;
			return await Task.Run (() => {

				var width = (int)(size.Width * scale);
				var height = (int)(size.Height * scale);

				using (var colorSpace = CoreGraphics.CGColorSpace.CreateDeviceRGB ()) {
					using (var c = new CoreGraphics.CGBitmapContext (
						              IntPtr.Zero,
						              width,
						              height,
						              8,
						              4 * width,
						              colorSpace,
						              CoreGraphics.CGImageAlphaInfo.NoneSkipFirst)) {

						c.TranslateCTM (0, height);
						c.ScaleCTM (scale, -scale);

						var g = new Praeclarum.Graphics.CoreGraphicsGraphics (c, true);
						App.DrawThumbnail (s, g, size, theme);

						//
						// Create the bitmap
						//
						return UIImage.FromImage (c.ToImage (), scale, UIImageOrientation.Up);
					}
				}
			});
		}
Exemplo n.º 2
0
		public DocumentsViewItem GetItemAtPoint (Praeclarum.Graphics.PointF p)
		{
			var index = IndexPathForRowAtPoint (Praeclarum.Graphics.RectangleEx.ToPointF (p));
			if (index == null)
				return null;

			var i = index.Row;

			return Items[i];
		}
Exemplo n.º 3
0
		public virtual async Task<UIImage> GenerateThumbnailAsync (DocumentReference docRef, Praeclarum.Graphics.SizeF size, Theme theme)
		{
			UIImage r = null;

			IDocument doc = null;
			LocalFileAccess local = null;
			var opened = false;

			//
			// Draw the document
			//
			try {
				local = await docRef.File.BeginLocalAccess ();
				var f = local.LocalPath;

				doc = App.CreateDocument (f);
				await doc.OpenAsync ();
				opened = true;

//				Console.WriteLine ("GenerateThumbnail: " + docRef.File.Path + " " + docRef.File.ModifiedTime);

				r = await GenerateDocumentThumbnailAsync (doc, size, theme);

			} catch (Exception ex) {
				Debug.WriteLine ("FAILED to genenerate thumbnail for {0}, {1}", docRef.File.Path, ex.Message);
//				Debug.WriteLine (ex);
			}

			if (opened) {
				try {
					await doc.CloseAsync ();					
				} catch (Exception ex) {
					Console.WriteLine (ex);
				}
			}

			if (local != null) {
				try {
					await local.End ();
				} catch (Exception ex) {
					Console.WriteLine (ex);
				}
			}

			return r;
		}
		public DocumentsViewItem GetItemAtPoint (Praeclarum.Graphics.PointF p)
		{
			var index = IndexPathForItemAtPoint (Praeclarum.Graphics.RectangleEx.ToPointF (p));
			if (index == null || index.Section == 0)
				return null;

			var i = index.Row - 1;

			if (0 <= i && i < Items.Count)
				return Items [i];

			return null;
		}