public ActionResult CropTypeList() { CropType ct = new CropType(); DataTable dt = ct.selectall(); return(View(dt)); }
private void CropDetailsSetup(ref CropDetailsViewModel cvm) { cvm.showCrude = false; cvm.typOptions = new List <SelectListItem>(); cvm.typOptions = _sd.GetCropTypesDll().ToList(); cvm.cropOptions = new List <SelectListItem>(); cvm.harvestUnitsOptions = new List <SelectListItem>(); if (!string.IsNullOrEmpty(cvm.selTypOption) && cvm.selTypOption != "select") { cvm.cropOptions = _sd.GetCropsDll(Convert.ToInt32(cvm.selTypOption)).ToList(); cvm.harvestUnitsOptions = _sd.GetCropHarvestUnitsDll().ToList(); if (cvm.selTypOption != "select") { CropType crpTyp = _sd.GetCropType(Convert.ToInt32(cvm.selTypOption)); cvm.showCrude = crpTyp.CrudeProteinRequired; cvm.coverCrop = crpTyp.CoverCrop; cvm.manEntry = crpTyp.CustomCrop; if (!crpTyp.CustomCrop) { cvm.cropOptions.Insert(0, new SelectListItem() { Id = 0, Value = "select" }); } } } PreviousCropSetup(ref cvm); return; }
public void Should_CropAndScale(CropType cropType, int width, int height, string expectedOutput) { using (var image = new MagickImage(Path.Join(_testFileDir, "alpine-lake_1920.jpg"))) { image.ScaleAndCrop(new Box(width, height), cropType); var actualBytes = image.ToByteArray(); var expectedOutputPath = Path.Join(_testFileDir, $"expected-output\\{expectedOutput}"); Assert.Equal(width, image.Width); Assert.Equal(height, image.Height); if (!File.Exists(expectedOutputPath)) { image.Write(expectedOutputPath); } else { using (var expectedOutputStream = File.OpenRead(Path.Join(_testFileDir, $"expected-output\\{expectedOutput}"))) { Assert.Equal(expectedOutputStream.ReadAllBytes(), actualBytes); } } } }
private void btnSend_Click(object sender, EventArgs e) { if (rdoGetInfoAllFields.Checked) { client.SendGetInfoAllFieldsCommand(); client.LastServerMessage.Fields.ForEach(x => { rtxtConsole.Text += x.ToString(); }); } else if (rdoGetInfoSingleField.Checked) { client.SendGetInfoSingleFieldCommand(cbxFieldName.Text); rtxtConsole.Text += client.LastServerMessage.FieldInfo.ToString(); } else if (rdoPlant.Checked) { CropType ct = new CropType(); Enum.TryParse <CropType>(cbxCropType.Text, out ct); var fieldInfo = new Field { Name = cbxFieldName.Text, Crop = new Crop(ct) }; client.SendPlantCommand(fieldInfo); rtxtConsole.Text += "Planted: " + client.LastServerMessage.FieldInfo.ToString(); } else if (rdoHarvest.Checked) { var fieldInfo = new Field(cbxFieldName.Text); client.SendHarvestCommand(fieldInfo); rtxtConsole.Text += "Harvested: " + client.LastServerMessage.FieldInfo.ToString(); } }
/// <summary> /// Add a crop to the worldgrid. /// </summary> /// <param name="y">The y coördinate containing the crop.</param> /// <param name="x">The x coördinate containing the crop.</param> /// <param name="cropType">The type of crop to add.</param> /// <returns>If the crop has been added.</returns> public bool AddCrop(byte y, byte x, CropType cropType) { //Check if position is out of bounds if (IsOutOfBound(y, x)) { return(false); } //Check if a crop is already present if (cells[y, x].CropIndex != -1) { return(false); } //Add the crop int cropIndex = GetNextCropId(); crops[cropIndex] = new Crop() { Type = cropType }; cells[y, x].CropIndex = cropIndex; return(true); }
public ActionResult CropTypeDelete(int ID) { CropType p = new CropType(); p.CropTypeID = ID; p.delete(); return(RedirectToAction("CropTypeList")); }
//------------Game Commands------------ public static byte[] AddCrop(byte y, byte x, CropType type) { byte[] data = CreateData(5, CommandType.AddCrop); data[2] = y; data[3] = x; data[4] = (byte)type; return(data); }
public void HandleAskToCreateCropType(AskToCreateCropType message) { Using <FarmForgeDataContext>((context) => { try { var existingClassification = context.CropClassifications .AsNoTracking() .Where(c => c.CropClassificationId == message.ClassificationId & c.IsDeleted == false ) .FirstOrDefault(); if (existingClassification == null) { throw new Exception("Classification not found"); } var existingType = context.CropTypes .AsNoTracking() .Where(t => t.Label == message.Name && t.IsDeleted == false ) .FirstOrDefault(); if (existingType != null) { throw new Exception("Type already exists"); } var name = message.Name.ToLower().Replace(" ", "_"); var newCropType = new CropType { CropClassificationId = message.ClassificationId, Name = name, Label = message.Name, Varieties = new List <CropVariety> { { new CropVariety { Name = "generic", Label = "Generic" } } } }; context.Add(newCropType); context.SaveChanges(); newCropType.Classification = existingClassification; Sender.Tell(newCropType); } catch (Exception ex) { Sender.Tell(ex); } }); }
public GrowableSeed(CropType cropType) : base(0xDCF) { this.Weight = 1.0; this.Stackable = Core.SA; this.Name = CropHelper.GetInfo(cropType).CropName + " seed"; this.Hue = CropHelper.GetInfo(cropType).CropHue; this.m_CropType = cropType; }
//------------Player Actions------------ public static byte[] PlantCrop(byte playerId, byte y, byte x, CropType type) { byte[] data = CreateData(6, CommandType.PlantCrop); data[2] = playerId; data[3] = y; data[4] = x; data[5] = (byte)type; return(data); }
/// <summary> /// Returns the name and full path of the requested crop /// </summary> public static string RequestedCropUrl(MediaFile file, CropType cropType) { string fileLocation = file.FileUrl; string temp = fileLocation.Replace(file.FileExtension, ""); temp += "_c" + cropType.Id; return(temp + file.FileExtension); }
public GrowableCrop(CropType cropType) : base(CropHelper.GetInfo(cropType).CropId) { this.Name = CropHelper.GetInfo(cropType).CropName + " seedling"; this.Movable = false; this.m_CropType = cropType; this.m_NbRessources = CropHelper.GetInfo(cropType).NbRessources; this.m_HarvestCount = CropHelper.GetInfo(cropType).HarvestMax; this.m_GrowTimer = new GrowTimer(this, CropHelper.GetInfo(cropType).GrowDuration); this.m_GrowTimer.Start(); }
private CropHelper(CropType cropType, String cropName, int cropHue, int cropId, int plantId, int growDuration, int nbRessources, int harvestMax) { this.m_CropType = cropType; this.m_CropName = cropName; this.m_CropHue = cropHue; this.m_CropId = cropId; this.m_PlantId = plantId; this.m_GrowDuration = growDuration; this.m_NbRessources = nbRessources; this.m_HarvestMax = harvestMax; }
public GameObject GetCropVisual(CropType _type, CropStage _stage) { switch (_type) { default: case CropType.Potato: return(PotatoVisuals[(int)_stage]); case CropType.Vegetable: return(VegetableVisuals[(int)_stage]); case CropType.Wheat: return(WheatVisuals[(int)_stage]); } }
public static Uri GetSpartanImage(string gamerTag, int size = 256, CropType cropType = CropType.Full) { var values = new NameValueCollection { { "size", size.ToString() }, { "crop", cropType.ToString().ToLower() } }; var baseUrl = string.Format("{0}/{1}/{2}/profiles/{3}/spartan", MajorPrefix, MinorPrefix, Title, gamerTag); return(values.BuildUri(baseUrl)); }
public ActionResult CropTypeEdit(int id) { CropType c = new CropType(); c.CropTypeID = id; c.SelectByID(); // CropType CT = new Models.CropType(); //ViewBag.dtCT = CT.selectall(); return(View(c)); }
//------------------------------------------------Crops Pages--------------------------------------------// public ActionResult Crops(int ID) { Crop P = new Crop(); DataTable dtProd = P.selectbycroptypeid(ID); CropType C = new CropType(); C.CropTypeID = ID; C.SelectCropTypeById(); ViewBag.Cat = C; return(View(dtProd)); }
public static CropHelper GetInfo(CropType plantType) { int index = (int)plantType; if (index >= 0 && index < m_Table.Length) { return(m_Table[index]); } else { return(m_Table[0]); } }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); this.m_CropType = (CropType)reader.ReadInt(); if (this.Weight != 1.0) this.Weight = 1.0; if (version < 1) this.Stackable = Core.SA; }
public async void CreateNewCropRun() { ChosenIsVacant = false; var settings = SettingsService.Instance; using (var db = new MainDbContext()) { //TODO: BUG here! Does not check if the CropType already exists correctly, tries to create new one regardless var cropType = _cropTypeCache.FirstOrDefault(ct => ct.Key.Equals(UserCropType.ToLower())).Value; if (cropType == null) { cropType = new CropType { Name = UserCropType, Approved = false, CreatedAt = DateTimeOffset.Now, CreatedBy = settings.CredStableSid }; db.Add(cropType); } else { db.Attach(cropType); } var cropCycle = new CropCycle { ID = Guid.NewGuid(), Name = "Unnamed", Yield = 0, CropType = cropType, CropTypeName = cropType.Name, CropVariety = CropVariety, LocationID = _chosenPlace.Location.ID, CreatedAt = DateTimeOffset.Now, UpdatedAt = DateTimeOffset.Now, StartDate = DateTimeOffset.Now, EndDate = null, Deleted = false, Version = new byte[32] }; db.CropCycles.Add(cropCycle); await db.SaveChangesAsync(); } await BroadcasterService.Instance.TablesChanged.Invoke(string.Empty); }
public ActionResult AddCropType(string inputCropLeafAreaIndex, string inputCropTypeName, string gidenBasari = "") { if (Session["KisiTanimlayici"].ToString() == "Customer") { TempData["SecurityWall_Home"] = "Güvenlik Duvarına Takıldınız."; return(RedirectToAction("Index", "Login")); } else { try { if (inputCropTypeName != null && inputCropLeafAreaIndex != "" && Convert.ToDouble(inputCropLeafAreaIndex) < 10) { OptagricEntities DB = new OptagricEntities(); CropType eklenecekNesne = new CropType { LeafAreaIndex = Convert.ToDouble(inputCropLeafAreaIndex), Name = inputCropTypeName }; DB.CropType.Add(eklenecekNesne); DB.SaveChanges(); //ActionLogs(Session["CurrentUserGuid"].ToString(), "Insert", "AddCropType"); //Aşağıdakilerde çalıştırılacak SİLME //CRUD_Logs("AddCropType", Session["CurrentUserGuid"].ToString(), "Insert", "AddCropType" + " " + "AdminPanel_CRUD"); string p1 = this.ControllerContext.RouteData.Values["action"].ToString(); string p2 = this.ControllerContext.RouteData.Values["controller"].ToString(); CRUD_Logs(p1, Session["CurrentUserGuid"].ToString(), "INSERT", eklenecekNesne.Name + " / " + p1 + " / " + p2); TempData["AddCropTypeSuccess"] = "Ekleme Başarılı"; return(View()); } else { TempData["AddCropTypeError"] = "Lütfen Değeleri Giriniz.Float değerleri girmek için ayraç olarak virgül kullanınız"; return(View()); } } catch (Exception) { TempData["AddCropTypeError"] = "Lütfen Değeleri Uygun Giriniz"; return(View()); } } }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadEncodedInt(); switch (version) { case 0: this.m_CropType = (CropType)reader.ReadInt(); this.m_NbRessources = (int)reader.ReadInt(); this.m_HarvestCount = (int)reader.ReadInt(); break; } this.m_GrowTimer = new GrowTimer(this, CropHelper.GetInfo(this.m_CropType).GrowDuration); this.m_GrowTimer.Start(); }
// This routine will typically be triggered after soil tests for a particular field have been updated // This routine will recalculate for all crops in a field the nutrients all that are dependant on the soil tests public void RecalcCropsSoilTestMessagesByField(string fieldName) { CalculateCropRequirementRemoval ccrr = new CalculateCropRequirementRemoval(_ud, _sd); //iterate through the crops and update the crop requirements List <FieldCrop> fieldCrops = _ud.GetFieldCrops(fieldName); if (fieldCrops.Count > 0) { foreach (var _crop in fieldCrops) { CropType crpTyp = new CropType(); FieldCrop cf = _ud.GetFieldCrop(fieldName, _crop.id); if (cf.cropId != null) { Crop cp = _sd.GetCrop(Convert.ToInt32(cf.cropId)); crpTyp = _sd.GetCropType(cp.croptypeid); } else { crpTyp.modifynitrogen = false; } CropRequirementRemoval crr = new CropRequirementRemoval(); ccrr.cropid = Convert.ToInt16(_crop.cropId); ccrr.previousCropid = _crop.prevCropId; ccrr.yield = _crop.yield; ccrr.crudeProtien = _crop.crudeProtien; ccrr.coverCropHarvested = _crop.coverCropHarvested; ccrr.fieldName = fieldName; crr = ccrr.GetCropRequirementRemoval(); if (!crpTyp.modifynitrogen) { cf.reqN = crr.N_Requirement; } cf.reqP2o5 = crr.P2O5_Requirement; cf.reqK2o = crr.K2O_Requirement; cf.remN = crr.N_Removal; cf.remP2o5 = crr.P2O5_Removal; cf.remK2o = crr.K2O_Removal; _ud.UpdateFieldCrop(fieldName, cf); } } }
public string SaveCroppedImage(string liveChequePath, CropType cropType, CropPoint cropPoints) { string savePath = ""; string CropName = cropType.ToString(); Random number = new Random(); Bitmap bitmap = new Bitmap(HttpContext.Current.Server.MapPath(liveChequePath)); Bitmap croppedBitmap = CropCheque(bitmap, cropPoints.CropStartX, cropPoints.CropStartY, cropPoints.CropWidth, cropPoints.CropHeight); HttpResponse response = GetHttpResponse(); response.ContentType = "image/jpeg"; savePath = "~/ChequeImageData/CroppedCheques/" + CropName + "/" + CropName + "_" + number.Next(0, 100000) + ".jpg"; croppedBitmap.Save(HttpContext.Current.Server.MapPath(savePath), ImageFormat.Jpeg); return(savePath); }
public void RemoveCropsFromCollection(CropType _type, int _amount) { switch (_type) { case CropType.Potato: amountOfPotatoes -= _amount; break; case CropType.Vegetable: amountOfVegetables -= _amount; break; case CropType.Wheat: amountOfWheat -= _amount; break; } }
public void AddCropsToCollection(CropType _type, int _amount) { switch (_type) { case CropType.Potato: amountOfPotatoes += _amount; break; case CropType.Vegetable: amountOfVegetables += _amount; break; case CropType.Wheat: amountOfWheat += _amount; break; } }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); this.m_CropType = (CropType)reader.ReadInt(); if (this.Weight != 1.0) { this.Weight = 1.0; } if (version < 1) { this.Stackable = Core.SA; } }
public ActionResult CropTypeUpdate(FormCollection collection) { CropType c = new CropType(); c.CropTypeID = Convert.ToInt32(collection["CropTypeID"]); c.SelectByID(); c.Name = collection["Name"]; if (Request.Files["Photo"].ContentLength > 0) { string path = "/croptypeimgs/" + DateTime.Now.Ticks.ToString() + "_" + Request.Files["Photo"].FileName; Request.Files["Photo"].SaveAs(Server.MapPath(path)); c.Photo = path; } c.update(); return(RedirectToAction("CropTypeList")); }
// This routine will typically be triggered after soil tests for a particular field have been updated // This routine will recalculate for all crops in a field the nutrients all that are dependant on the soil tests public Field RecalcCropsSoilTestMessagesByField(Field field, int farmRegionId) { //iterate through the crops and update the crop requirements var fieldResult = field; var fieldCrops = fieldResult.Crops; if (fieldCrops.Count > 0) { foreach (var crop in fieldCrops) { CropType crpTyp = new CropType(); if (crop.cropId != null) { Crop cp = _sd.GetCrop(Convert.ToInt32(crop.cropId)); crpTyp = _sd.GetCropType(cp.CropTypeId); } else { crpTyp.ModifyNitrogen = false; } var crr = _calculateCropRequirementRemoval.GetCropRequirementRemoval( Convert.ToInt16(crop.cropId), crop.yield, crop.crudeProtien, crop.coverCropHarvested, 0, farmRegionId, field); if (!crpTyp.ModifyNitrogen) { crop.reqN = crr.N_Requirement; } crop.reqP2o5 = crr.P2O5_Requirement; crop.reqK2o = crr.K2O_Requirement; crop.remN = crr.N_Removal; crop.remP2o5 = crr.P2O5_Removal; crop.remK2o = crr.K2O_Removal; } } return(fieldResult); }
public static MagickImage ScaleAndCrop(this MagickImage image, Box box, CropType cropType = CropType.Center) { var imageWHRatio = (decimal)image.Width / image.Height; var outputWHRatio = (decimal)box.Width / box.Height; var outputIsWider = outputWHRatio > imageWHRatio; if (outputIsWider) { image.ScaleByWidth(box.Width); } else { image.ScaleByHeight(box.Height); } image.Crop(box, cropType); return(image); }
public static MagickImage Crop(this MagickImage image, Box box, CropType cropType) { if (cropType == CropType.Center) { var imageToOutputWidthDiff = image.Width - box.Width; var imageToOutputHeightDiff = image.Height - box.Height; image.Crop(new MagickGeometry(box.Width, box.Height) { X = (imageToOutputWidthDiff) / 2 - (imageToOutputWidthDiff) / 2 / 2, Y = (imageToOutputHeightDiff) / 2 - (imageToOutputHeightDiff) / 2 / 2 }); } else { throw new UnknownCropTypeException(); } return(image); }
/// <summary> /// Return the current string cropped by number of words or characters. /// <para> /// Words: returns the first "xNumber" of words in the string, including any intermediate punctuation, etc. /// Trailing punctuation is always removed. /// </para> /// <para> /// Characters: returns the first "xNumber" of characters in the string, including any intermediate punctuation, etc. /// When it locates the last character, it scans ahead to make sure it's not breaking a word. If it is in the middle /// of a word, it will skip ahead to the next non-alpha-numeric chatacter and break on that, so your cropped string /// may be slightly larger than the number of characters you requested. Trailing punctuation is always removed. /// </para> /// </summary> /// <example> /// <code> /// using Mezzocode.Halide3; /// ... /// string sourceStr = "now is the time"; /// string result = h3Text.Crop(sourceStr, 3, h3Text.CropType.Words, " .,;:!?", "..."); /// </code> /// result would be "now is the...". /// </example> /// <param name="strvar">String to process.</param> /// <param name="xNumber">Number of words or characters (as close as possible) to return.</param> /// <param name="cropType">Enum value: CropType.Characters or CropType.Words.</param> /// <param name="xChars">Valid characters on which to break (defaults to space characters).</param> /// <param name="endWhenCropped">String to append to the return value, only if the string had to be cropped.</param> /// <returns>A cropped string</returns> public static String Crop(string strvar, int xNumber, CropType cropType, string xChars, string endWhenCropped) { string outt = strvar; if (xNumber > 0) { switch (cropType) { case CropType.Words: Regex x = new Regex(@"((\w*?)(\W|\z)){0," + xNumber + @"}", RegexOptions.Singleline); MatchCollection mc = x.Matches(strvar); outt = mc[0].ToString(); break; case CropType.Characters: string breakOn = xChars; if (String.IsNullOrEmpty(breakOn)) { breakOn = " "; } int test = 0; int index = outt.Length; if (strvar.Length > xNumber) { for (int X = 0; X < breakOn.Length; X++) { test = outt.IndexOf(breakOn.Substring(X, 1), xNumber); if (test < index && test >= xNumber) { index = test; } } if (index < 1 || index >= outt.Length) { index = xNumber; } else { index++; } outt = strvar.Substring(0, index); } break; } if (outt.Length < strvar.Length) { while (outt.Length > 0 && !h3Identify.HasPattern(h3Identify.REGEX_IS_ALPHA_NUMBER_ONLY, outt.Substring(outt.Length - 1, 1))) { outt = outt.Substring(0, outt.Length - 1); } outt += endWhenCropped; } } return outt; }
/// <summary> /// Return the current string cropped by number of words or characters. /// <para> /// Words: returns the first "xNumber" of words in the string, including any intermediate punctuation, etc. /// Trailing punctuation is always removed. /// </para> /// <para> /// Characters: returns the first "xNumber" of characters in the string, including any intermediate punctuation, etc. /// When it locates the last character, it scans ahead to make sure it's not breaking a word. If it is in the middle /// of a word, it will skip ahead to the next non-alpha-numeric chatacter and break on that, so your cropped string /// may be slightly larger than the number of characters you requested. Trailing punctuation is always removed. /// </para> /// </summary> /// <example> /// <code> /// string sourceStr = "now is the time"; /// h3Text sj = new h3Text(); /// string result = h3Text.Crop(sourceStr, 3, h3Text.CropType.Words, " .,;:!?"); /// </code> /// result would be "now is the". /// </example> /// <param name="strvar">String to process.</param> /// <param name="xNumber">Number of words or characters to return (as close as possible).</param> /// <param name="cropType">Enum value: CropType.Characters or CropType.Words.</param> /// <param name="xChars">Valid characters to break on (defaults to space characters).</param> /// <returns>A cropped string</returns> public static String Crop(string strvar, int xNumber, CropType cropType, string xChars) { return Crop(strvar, xNumber, cropType, xChars, ""); }
/// <summary> /// Return the current string cropped by number of words or characters. /// <para> /// Words: returns the first "xNumber" of words in the string, including any intermediate punctuation, etc. /// Trailing punctuation is always removed. /// </para> /// <para> /// Characters: returns the first "xNumber" of characters in the string, including any intermediate punctuation, etc. /// When it locates the last character, it scans ahead to make sure it's not breaking a word. If it is in the middle /// of a word, it will skip ahead to the next non-alpha-numeric chatacter and break on that, so your cropped string /// may be slightly larger than the number of characters you requested. Trailing punctuation is always removed. /// </para> /// </summary> /// <example> /// <code> /// string sourceStr = "now is the time"; /// h3Text sj = new h3Text(); /// string result = h3Text.Crop(sourceStr, 3, h3Text.CropType.Words); /// </code> /// result would be "now is the". /// </example> /// <param name="strvar">String to process.</param> /// <param name="xNumber">Number of words or characters to return (as close as possible).</param> /// <param name="cropType">Enum value: CropType.Characters or CropType.Words.</param> /// <returns>A cropped string</returns> public static String Crop(string strvar, int xNumber, CropType cropType) { return Crop(strvar, xNumber, cropType, "", ""); }
public static CropHelper GetInfo(CropType plantType) { int index = (int)plantType; if (index >= 0 && index < m_Table.Length) return m_Table[index]; else return m_Table[0]; }
public static async Task CropImageAsync(string sourceImageFile, string destinationImageFile, double scaleFactor, Rect clipRect, CropType cropType = CropType.UseScaleFactor) { byte[] sourcePixels; BitmapTransform transform; BitmapDecoder bmpDecoder; using (var srcStream = await (await StorageFile.GetFileFromPathAsync(sourceImageFile)).OpenAsync(FileAccessMode.Read)) { bmpDecoder = await BitmapDecoder.CreateAsync(srcStream); if (cropType == CropType.GetLargestRect) { // calculate scale factor to be minimal while still fitting the rect double sx, sy; sx = clipRect.Width / bmpDecoder.PixelWidth; sy = clipRect.Height / bmpDecoder.PixelHeight; scaleFactor = Math.Max(sx, sy); } transform = new BitmapTransform() // scale source bitmap to size of drawn image { ScaledHeight = (uint)(bmpDecoder.PixelHeight * scaleFactor), ScaledWidth = (uint)(bmpDecoder.PixelWidth * scaleFactor), InterpolationMode = BitmapInterpolationMode.Fant }; // decode data and get binary data var pixelData = await bmpDecoder.GetPixelDataAsync(BitmapPixelFormat.Rgba16, BitmapAlphaMode.Straight, transform, ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage); sourcePixels = pixelData.DetachPixelData(); } using (var dstStream = await (await CreateOrOpenFileAsync(destinationImageFile)).OpenAsync(FileAccessMode.ReadWrite)) { // create encoder to save data dstStream.Size = 0; var ext = destinationImageFile.Substring(destinationImageFile.LastIndexOf('.') + 1); Guid encId; switch (ext.ToLowerInvariant()) { case "jpg": case "jpeg": encId = BitmapEncoder.JpegEncoderId; break; case "gif": encId = BitmapEncoder.GifEncoderId; break; case "png": encId = BitmapEncoder.PngEncoderId; break; case "bmp": encId = BitmapEncoder.BmpEncoderId; break; case "tif": case "tiff": encId = BitmapEncoder.TiffEncoderId; break; } var bmpEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, dstStream); // set data bmpEncoder.SetPixelData(BitmapPixelFormat.Rgba16, BitmapAlphaMode.Straight, transform.ScaledWidth, transform.ScaledHeight, bmpDecoder.DpiX, bmpDecoder.DpiY, sourcePixels); // apply crop bmpEncoder.BitmapTransform.Bounds = new BitmapBounds() { X = (uint)clipRect.X, Y = (uint)clipRect.Y, Width = (uint)clipRect.Width, Height = (uint)clipRect.Height }; bmpEncoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Fant; // save await bmpEncoder.FlushAsync(); } }
/// <summary> /// Sets the type. /// </summary> /// <param name='t'> /// the type as an int. /// </param> public void setType(int t) { ct = (CropType)t; }
private void crop(CropType type) { int valToBeat = 0; int xyIdx = 0; bool lowest = false; switch (type) { case CropType.LOWEST_X: valToBeat = PositionStatistics.MAX_X; xyIdx = 0; lowest = true; break; case CropType.HIGHEST_X: valToBeat = 0; xyIdx = 0; lowest = false; break; case CropType.LOWEST_Y: valToBeat = PositionStatistics.MAX_Y; xyIdx = 1; lowest = true; break; case CropType.HIGHEST_Y: valToBeat = 0; xyIdx = 1; lowest = false; break; } string[] points = currentLine.Split(';'); int idx = points.Length - 1; for (; idx > 0; idx--) { string xy = points[idx]; if (xy == null || xy.Equals("")) continue; string[] point = xy.Split(','); if (point.Length == 2) { int val = int.Parse(point[xyIdx]); if ((lowest && val <= valToBeat) || (!lowest && val >= valToBeat)) { valToBeat = val; } else { break; } } } var sb = new StringBuilder(); for (int i = 0; i <= idx; i++) { sb.Append(points[i]); sb.Append(";"); } currentLine = sb.ToString(); displayLine(currentLine); }
public async Task<Image> GetSpartanImage(string gamerTag, int size = 256, CropType cropType = CropType.Full) { return await _responseProcessor.ProcessImageRequest(Endpoints.Profile.GetSpartanImage(gamerTag, size, cropType), ProfileCacheExpirty); }
public static Uri GetSpartanImage(string gamerTag, int size = 256, CropType cropType = CropType.Full) { var values = new NameValueCollection { {"size", size.ToString()}, {"crop", cropType.ToString().ToLower()} }; var baseUrl = string.Format("{0}/{1}/{2}/profiles/{3}/spartan", MajorPrefix, MinorPrefix, Title, gamerTag); return values.BuildUri(baseUrl); }