public void DrawPath(Cell cell, Rectangle pathRect, Point direction, CellColor color) { mContext.DrawImage(pathRect, UIImageEx.GetImageWithOverlayColor(mPathImage, color.UIColor).CGImage); // The old drawing code for perfect paths // context.SetFillColor (color.UIColor.CGColor); // Draw in 2 parts: // First a rect // context.FillRect (pathRect); // // // Then an arc to the end // if (direction.X < 0) { // context.MoveTo (pathRect.Right, pathRect.Top); // context.AddCurveToPoint ( // pathRect.Right + pathRect.Width / 3, // pathRect.Top + pathRect.Height / 3, // pathRect.Right + pathRect.Width / 3, // pathRect.Top + 2 * pathRect.Height / 3, // pathRect.Right, // pathRect.Bottom // ); // } else if (direction.X > 0) { // context.MoveTo (pathRect.Left, pathRect.Top); // context.AddCurveToPoint ( // pathRect.Left - pathRect.Width / 3, // pathRect.Top + pathRect.Height / 3, // pathRect.Left - pathRect.Width / 3, // pathRect.Top + 2 * pathRect.Height / 3, // pathRect.Left, // pathRect.Bottom // ); // } // if (direction.Y < 0) { // context.MoveTo (pathRect.Left, pathRect.Bottom); // context.AddCurveToPoint ( // pathRect.Left + pathRect.Width / 3, // pathRect.Bottom + pathRect.Height / 3, // pathRect.Left + 2 * pathRect.Width / 3, // pathRect.Bottom + pathRect.Height / 3, // pathRect.Right, // pathRect.Bottom // ); // } else if (direction.Y > 0) { // context.MoveTo (pathRect.Left, pathRect.Top); // context.AddCurveToPoint ( // pathRect.Left + pathRect.Width / 3, // pathRect.Top - pathRect.Height / 3, // pathRect.Left + 2 * pathRect.Width / 3, // pathRect.Top - pathRect.Height / 3, // pathRect.Right, // pathRect.Top // ); // } // // context.FillPath (); }
public void FilterImage(UIImage img, int difficulty) { if (mLastDifficulty != difficulty) { mLastDifficulty = difficulty; if (mFilterThread != null) { mFilterThread.Abort(); mFilterThread = null; } mFilterThread = new Thread(() => { this.mImageToUse = img; // Slight saturation mImageToUse = UIImageEx.AdjustBrightnessSaturationAndContrast(mImageToUse, 0, 1.2f); int size = HARD_SIZE; if (difficulty <= 0) { size = NORMAL_SIZE; } else if (difficulty > 0 && difficulty <= 1) { size = HARD_SIZE; } else if (difficulty > 1) { size = EXPERT_SIZE; } mImageToUse = ImageFilters.Filter(mImageToUse, size); InvokeOnMainThread(() => { if (ImageTransformed != null) { ImageTransformed.Image = mImageToUse; } }); }); mFilterThread.Start(); } }
public void DrawCellBase(Cell cell) { bool isValid = cell.Path != null && cell.Path.IsValid; CellColor cellColor = cell.Color; if (cell.Path != null) { cellColor = cell.Path.Color; } CGColor color = cellColor.UIColor.CGColor; mContext.SetFillColor(color); if (mParent.ShouldDisplayFilledCells == false) { // Draw a circle of the color // But reduce the circle value int circleReductionValue = mParent.CellSize / 10; RectangleF cellValueRect = new RectangleF(cell.Rect.X + circleReductionValue, cell.Rect.Y + circleReductionValue, mParent.CellSize - 2 * circleReductionValue, mParent.CellSize - 2 * circleReductionValue); UIImage image = null; if (isValid == false) { image = mSplashImage; image = UIImageEx.GetImageWithOverlayColor(image, cellColor.UIColor); mContext.DrawImage(cellValueRect, image.CGImage); } else { mContext.FillRect(cell.Rect); } } else { // Fill the whole cell to preview puzzle mContext.FillRect(cell.Rect); } }
private static List <Color> getColorPalette(UIImage img, int paletteColorsNumber) { // -- Make a thumbnail for better performace Logger.D("Palette -> resize"); UIImage thumb = UIImageEx.ResizeRatio(img, Math.Min(96, (int)Math.Max(img.Size.Width, img.Size.Height))); Bitmap thumbBitmap = new Bitmap(thumb); // -- Get each colors Logger.D("Palette -> get each color"); Dictionary <Color, int> rawColorList = new Dictionary <Color, int> (); for (int xq = 0; xq < thumb.Size.Width; xq++) { for (int yq = 0; yq < thumb.Size.Height; yq++) { Color c = thumbBitmap.GetPixel(xq, yq); if (rawColorList.ContainsKey(c)) { rawColorList [c] += 1; } else { rawColorList.Add(c, 1); } } // for y } // for x var orderedColorList = rawColorList .Where(c => c.Value > 1) // Take only colors that appear at least twice (huge optim) .OrderByDescending(c => c.Value) // Order by frequency .Select(c => c.Key) // Select only keys .ToList(); // -- Look if we have a similar color already in the palette Logger.D("Palette -> restrict to n"); List <Color> colorPalette = new List <Color> (paletteColorsNumber); while (colorPalette.Count < paletteColorsNumber) { if (orderedColorList.Any() == false) { Logger.W("Palette -> Not enough color!"); break; } Color c1 = orderedColorList.First(); List <Color> similarColors = new List <Color> (); similarColors.Add(c1); int avg_r = c1.R; int avg_b = c1.B; int avg_g = c1.G; // Look for similar colors foreach (Color c2 in orderedColorList) { if (c1 == c2) { continue; } double distance = Math.Abs(Math.Pow(c1.R - c2.R, 2) + Math.Pow(c1.G - c2.G, 2) + Math.Pow(c1.B - c2.B, 2)); if (distance < PaletteColorDifferenceThreshold) { // Too close, do the average avg_r += c2.R; avg_g += c2.G; avg_b += c2.B; similarColors.Add(c2); } } // Add the average colors Color newColor = Color.FromArgb( avg_r / similarColors.Count, avg_g / similarColors.Count, avg_b / similarColors.Count ); colorPalette.Add(newColor); // Remove checked colors foreach (var deletedColor in similarColors) { orderedColorList.Remove(deletedColor); } } // Free things thumbBitmap = null; return(colorPalette); }
private void PrepareCell(UITableViewCell cell) { cell.Accessory = Accessory; var tl = cell.TextLabel; tl.Text = Caption; tl.TextAlignment = Alignment; tl.TextColor = TextColor ?? UIColor.Black; tl.Font = Font ?? UIFont.BoldSystemFontOfSize(17); tl.LineBreakMode = LineBreakMode; tl.Lines = Lines; // The check is needed because the cell might have been recycled. if (cell.DetailTextLabel != null) { cell.DetailTextLabel.Text = Value == null ? "" : Value; } if (extraInfo == null) { cell.ContentView.BackgroundColor = null; tl.BackgroundColor = null; } else { var imgView = cell.ImageView; UIImage img; if (extraInfo.Image != null) { img = extraInfo.Image; } else { img = null; } imgView.Image = img; // http://stackoverflow.com/questions/1269188/iphone-sdk-adding-a-uiactivityindicatorview-to-a-uitableviewcell if (extraInfo.Activity) { if (_spinner == null) { _spinner = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Gray); _spinner.Frame = new System.Drawing.RectangleF(0, 0, 25, 25); _whiteback = UIImageEx.FromFile(@"Images/whiteback.png"); } cell.ImageView.Image = _whiteback; cell.ImageView.AddSubview(_spinner); if (!_spinner.IsAnimating) { _spinner.StartAnimating(); } } else { if (_spinner != null) { _spinner.StopAnimating(); _spinner.RemoveFromSuperview(); _spinner = null; _whiteback = null; } } if (cell.DetailTextLabel != null) { cell.DetailTextLabel.TextColor = extraInfo.DetailColor ?? UIColor.Black; } var badgeCell = cell as BadgeTableViewCell; if (badgeCell != null && extraInfo.New) { badgeCell.BadgeView.TextLabel.Text = @"New"; badgeCell.BadgeView.BadgeColor = new UIColor(0.388f, 0.686f, 0.239f, 1.0f); } if (cell.DetailTextLabel != null) { cell.DetailTextLabel.Lines = Lines; cell.DetailTextLabel.LineBreakMode = LineBreakMode; cell.DetailTextLabel.Font = SubtitleFont ?? UIFont.SystemFontOfSize(14); } } }