private static void ProcessImages(WriteableBitmap wb, List <string> localUris, List <Rect> map, Action <string> callback, int ind, long userOrChatId, bool isChat) { if (ind >= localUris.Count || ind >= map.Count) { Rectangle rectangle = new Rectangle(); rectangle.Width = (double)ConversationTileImageFormatter.DIMENSION; rectangle.Height = (double)ConversationTileImageFormatter.DIMENSION; rectangle.Fill = (Brush) new SolidColorBrush(Colors.Black); rectangle.Opacity = 0.2; wb.Render((UIElement)rectangle, (Transform)null); wb.Invalidate(); using (IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication()) { string path = "/Shared/ShellContent/conversationTileImg" + (object)userOrChatId + isChat.ToString() + ".jpg"; if (!storeForApplication.DirectoryExists("/Shared/ShellContent")) { storeForApplication.CreateDirectory("/Shared/ShellContent"); } using (IsolatedStorageFileStream storageFileStream = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, storeForApplication)) { int targetWidth = ConversationTileImageFormatter.DIMENSION; int targetHeight = ConversationTileImageFormatter.DIMENSION; wb.SaveJpeg((Stream)storageFileStream, targetWidth, targetHeight, 0, 80); } callback(path); } } else { string uri = localUris[ind]; Rect rect = map[ind]; double width = rect.Width; rect = map[ind]; double height = rect.Height; Image image1 = ConversationTileImageFormatter.CreateImage(uri, width, height); WriteableBitmap writeableBitmap = wb; Image image2 = image1; TranslateTransform translateTransform = new TranslateTransform(); rect = map[ind]; double x = rect.X; translateTransform.X = x; rect = map[ind]; double y = rect.Y; translateTransform.Y = y; writeableBitmap.Render((UIElement)image2, (Transform)translateTransform); ConversationTileImageFormatter.ProcessImages(wb, localUris, map, callback, ind + 1, userOrChatId, isChat); } }
public static void CreateTileImage(List <string> localUris, long userOrChatId, bool isChat, Action <string> callback) { Execute.ExecuteOnUIThread((Action)(() => { try { WriteableBitmap wb = new WriteableBitmap(ConversationTileImageFormatter.DIMENSION, ConversationTileImageFormatter.DIMENSION); localUris = localUris.Where <string>((Func <string, bool>)(u => !string.IsNullOrWhiteSpace(u))).ToList <string>(); List <Rect> map1 = ConversationTileImageFormatter.CreateMap(localUris.Count, isChat); List <string> localUris1 = localUris; List <Rect> map2 = map1; Action <string> callback1 = callback; int ind = 0; long userOrChatId1 = userOrChatId; int num = isChat ? 1 : 0; ConversationTileImageFormatter.ProcessImages(wb, localUris1, map2, callback1, ind, userOrChatId1, num != 0); } catch (Exception ex) { callback(""); Logger.Instance.Error("CreateTileImage failed. " + (object)ex); } })); }
private static void ProcessImages(WriteableBitmap wb, List <string> localUris, List <Rect> map, Action <string> callback, int ind, long userOrChatId, bool isChat) { if (ind >= localUris.Count || ind >= map.Count) { Rectangle rectangle = new Rectangle(); ((FrameworkElement)rectangle).Width = ((double)ConversationTileImageFormatter.DIMENSION); ((FrameworkElement)rectangle).Height = ((double)ConversationTileImageFormatter.DIMENSION); ((Shape)rectangle).Fill = ((Brush) new SolidColorBrush(Colors.Black)); ((UIElement)rectangle).Opacity = 0.2; wb.Render((UIElement)rectangle, null); wb.Invalidate(); IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication(); try { string str = string.Concat(new object[4] { "/Shared/ShellContent/conversationTileImg", userOrChatId, isChat.ToString(), ".jpg" }); if (!storeForApplication.DirectoryExists("/Shared/ShellContent")) { storeForApplication.CreateDirectory("/Shared/ShellContent"); } IsolatedStorageFileStream storageFileStream = new IsolatedStorageFileStream(str, (FileMode)2, (FileAccess)2, storeForApplication); try { int dimension1 = ConversationTileImageFormatter.DIMENSION; int dimension2 = ConversationTileImageFormatter.DIMENSION; System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, (Stream)storageFileStream, dimension1, dimension2, 0, 80); } finally { if (storageFileStream != null) { ((IDisposable)storageFileStream).Dispose(); } } callback(str); } finally { if (storeForApplication != null) { ((IDisposable)storeForApplication).Dispose(); } } } else { string localUri = localUris[ind]; Rect rect = map[ind]; // ISSUE: explicit reference operation double width = rect.Width; rect = map[ind]; // ISSUE: explicit reference operation double height = rect.Height; Image image1 = ConversationTileImageFormatter.CreateImage(localUri, width, height); WriteableBitmap writeableBitmap = wb; Image image2 = image1; TranslateTransform translateTransform = new TranslateTransform(); rect = map[ind]; // ISSUE: explicit reference operation double x = rect.X; translateTransform.X = x; rect = map[ind]; // ISSUE: explicit reference operation double y = rect.Y; translateTransform.Y = y; writeableBitmap.Render((UIElement)image2, (Transform)translateTransform); ConversationTileImageFormatter.ProcessImages(wb, localUris, map, callback, ind + 1, userOrChatId, isChat); } }