public IActionResult Put([FromBody] AvatarImage avatar) { if (avatar == null || avatar.B64Data == null || avatar.B64Data.Length == 0) { return(BadRequest(_localizer[Strings.EmptyImageData].Value)); } ImageEntry image = new ImageEntry { Id = avatar.Id, PersonId = avatar.PersonId }; try { image.SetB64Data(avatar.B64Data); if (image.Data == null || image.Data.Length == 0) { throw new Exception("Invalid B64Data"); } } catch (Exception e) { // don't let b64 decoding failure result in Internal Server error Console.WriteLine(string.Format("PUT api/image: {0}: id {1}, personId {2}, b64Data {3}", e.Message, avatar.Id, avatar.PersonId, avatar.B64Data)); return(BadRequest(_localizer[Strings.InvalidImageData].Value)); } return(StoreAvatarImage(image)); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); // var baseEntry = (ImageEntry)Element; if (!((Control != null) & (e.NewElement != null))) { return; } var entryExt = (e.NewElement as ImageEntry); if (entryExt == null) { return; } Control.ImeOptions = entryExt.ReturnKeyType.GetValueFromDescription(); Control.SetImeActionLabel(entryExt.ReturnKeyType.ToString(), Control.ImeOptions); Control.EditorAction += (sender, args) => { baseEntry.EntryActionFired(); }; // if (e.OldElement != null || e.NewElement == null) { return; } element = (ImageEntry)this.Element; var editText = this.Control; if (!string.IsNullOrEmpty(element.Image)) { switch (element.ImageAlignment) { case ImageAlignment.Left: editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(element.Image), null, null, null); break; case ImageAlignment.Right: editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, GetDrawable(element.Image), null); break; } } editText.CompoundDrawablePadding = 30; editText.TextAlignment = Android.Views.TextAlignment.Gravity; editText.VerticalFadingEdgeEnabled = true; Control.Background = null; // Control.Background.SetColorFilter(element.LineColor.ToAndroid(), PorterDuff.Mode.SrcAtop); }
public ActionResult <byte[]> GetImageById(string id) { if (string.IsNullOrWhiteSpace(id)) { return(BadRequest(_localizer[Strings.EmptyImageId].Value)); } ImageEntry entry = GetExistingImage(id); if (entry == null) { return(NotFound(_localizer[Strings.ImageIdNotFound, id].Value)); } // determine image type from extension in entry.Id switch (Path.GetExtension(entry.Id).ToLower()) { case "jpg": case "jpeg": return(File(entry.Data, "image/jpeg; charset=UTF-8", entry.Id)); } // default to png return(File(entry.Data, "image/png; charset=UTF-8", entry.Id)); }
public void AddAvatar(IFormFile pvm, int UserID) { ImageEntry person = new ImageEntry(); ProfileManager profile = new ProfileManager(_context); if (pvm != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(pvm.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)pvm.Length); } person.Image = imageData; } int id = profile.GetIn(UserID).ImageId; if (id != 0) { _context.Images.FirstOrDefault(Im => Im.ID == id).Image = person.Image; } else { _context.Images.Add(person); _context.SaveChanges(); _context.Profiles.FirstOrDefault(profile => profile.ID == UserID).ImageId = _context.Images.ToList().Last().ID; } _context.SaveChanges(); }
private Image <Rgba32>[] GetFrames(ImageEntry entry, int frameWidth, int frameHeight) { var source = entry.Image; int framesInWidth = source.Width / frameWidth; int framesInHeight = source.Height / frameHeight; //List<Image<Rgba32>> result = new List<Image<Rgba32>>(); Image <Rgba32>[] result = new Image <Rgba32> [framesInHeight * framesInWidth]; int counter = 0; for (int x = 0; x < framesInWidth; x++) { for (int y = 0; y < framesInHeight; y++) { var x1 = x; var y1 = y; var newBitmap = entry.Image.Clone( img => img.Crop( new Rectangle( new Point(x1 * frameWidth, y1 * frameHeight), new Size(frameWidth, frameHeight)))); result[counter++] = newBitmap; } } return(result); }
public int CompareTo(object _rhs) { ImageEntry rhs = _rhs as ImageEntry; if (rhs == null) { return(1); } ImageValidatorData.ImageEntryColumnData columnThis = new ImageValidatorData.ImageEntryColumnData(Name); ImageValidatorData.ImageEntryColumnData columnRhs = new ImageValidatorData.ImageEntryColumnData(rhs.Name); try { float timeThis = float.Parse(columnThis.Time); float timeRhs = float.Parse(columnRhs.Time); int x = timeThis.CompareTo(timeRhs); if (x != 0) { return(x); } } catch (Exception) { // if time is not part of the name we cannot sort by it } return(Name.CompareTo(rhs.Name)); }
protected async override void OnElementChanged(ElementChangedEventArgs <Entry> e) { try { base.OnElementChanged(e); if (e.OldElement != null || e.NewElement == null) { return; } element = (ImageEntry)this.Element; var editText = this.Control; if (!string.IsNullOrEmpty(element.Image)) { switch (element.ImageAlignment) { case ImageAlignment.Left: editText.SetCompoundDrawablesWithIntrinsicBounds(await GetDrawable(element.Image), null, null, null); break; case ImageAlignment.Right: editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, await GetDrawable(element.Image), null); break; } } editText.CompoundDrawablePadding = 25; Control.Background.SetColorFilter(Android.Graphics.Color.Rgb(48, 48, 48), PorterDuff.Mode.SrcAtop); } catch (Exception) { //in case any unknown exception in render prevent any notification or bubble } }
private static void CorrectSnapshotScaleX(ImageEntry entry, Texture tex, SerializedProperty entryProperty) { var size = entry.snapshotScale * new Vector2(tex.width, tex.height); var fix = Mathf.Abs((1.0f / SnapshotAspectRatio) / (size.x / size.y)); entryProperty.FindPropertyRelative("snapshotScale.x").floatValue *= fix; }
private XElement ToImageElement(ImageEntry entry) { var imageElement = new XElement(ImageNamespace + "image", new XElement(ImageNamespace + "loc", mUrlHelper.MakeAbsolute(entry.Url))); if (!String.IsNullOrWhiteSpace(entry.Title)) { imageElement.Add(new XElement(ImageNamespace + "title", entry.Title)); } if (!String.IsNullOrWhiteSpace(entry.Caption)) { imageElement.Add(new XElement(ImageNamespace + "caption", entry.Caption)); } if (!String.IsNullOrWhiteSpace(entry.GeoLocation)) { imageElement.Add(new XElement(ImageNamespace + "geo_location", entry.GeoLocation)); } if (!String.IsNullOrWhiteSpace(entry.LicenseUrl)) { imageElement.Add(new XElement(ImageNamespace + "license", entry.LicenseUrl)); } return(imageElement); }
private void CallUpdate(ImageEntry entry) { if (UpdateEntry != null) { UpdateEntry(entry); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement != null || e.NewElement == null) { return; } element = (ImageEntry)this.Element; var editText = this.Control; if (!string.IsNullOrEmpty(element.Image)) { switch (element.ImageAlignment) { case ImageAlignment.Left: editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(element.Image), null, null, null); break; case ImageAlignment.Right: editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, GetDrawable(element.Image), null); break; } } editText.CompoundDrawablePadding = 25; Control.Background.SetColorFilter(element.LineColor.ToAndroid(), PorterDuff.Mode.SrcAtop); }
private void DrawPreview(string path, ImageEntry entry, SerializedProperty entryProperty) { var sprite = Resources.Load <Sprite>(path); if (sprite == null) { EditorGUILayout.HelpBox("Invalid image resource path!", MessageType.Error); return; } if (GUILayout.Button("Correct Snapshot Scale Y for Aspect Ratio")) { CorrectSnapshotScaleY(entry, sprite.texture, entryProperty); } if (GUILayout.Button("Correct Snapshot Scale X for Aspect Ratio")) { CorrectSnapshotScaleX(entry, sprite.texture, entryProperty); } if (GUILayout.Button("Reset Snapshot Scale Offset")) { ResetSnapshotScaleOffset(entryProperty); } var height = EditorGUIUtility.currentViewWidth / sprite.texture.width * sprite.texture.height; var rect = EditorGUILayout.GetControlRect(false, height); EditorGUI.DrawPreviewTexture(rect, sprite.texture); if (previewDrawSnapshotFrame) { DrawPreviewSnapshotFrame(entry, rect); } }
private IEnumerable <SopInstance> GetSopInstances(ImageEntry criteria) { try { string studyInstanceUid = null, seriesInstanceUid = null; if (criteria != null && criteria.Image != null) { studyInstanceUid = criteria.Image.StudyInstanceUid; seriesInstanceUid = criteria.Image.SeriesInstanceUid; } //This will throw when either Uid parameter is empty. var series = GetSeries(studyInstanceUid, seriesInstanceUid); if (series == null) { return(new List <SopInstance>()); } //TODO (Marmot): make extended data queryable, too. var dicomCriteria = criteria.Image.ToDicomAttributeCollection(); var filters = new SopInstancePropertyFilters(dicomCriteria); var results = filters.FilterResults(series.GetSopInstances().Cast <SopInstance>()); return(results); } catch (Exception e) { throw new Exception("An error occurred while performing the image query.", e); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement != null || e.NewElement == null) { return; } element = (ImageEntry)this.Element; //set border if (element.IsCurvedCornersEnabled) { // creating gradient drawable for the curved background var _gradientBackground = new GradientDrawable(); _gradientBackground.SetShape(ShapeType.Rectangle); _gradientBackground.SetColor(element.BackgroundColor.ToAndroid()); // Thickness of the stroke line _gradientBackground.SetStroke(element.BorderWidth, element.BorderColor.ToAndroid()); // Radius for the curves _gradientBackground.SetCornerRadius( DpToPixels(this.Context, Convert.ToSingle(element.CornerRadius))); // set the background of the label Control.SetBackground(_gradientBackground); } // Set padding for the internal text from border Control.SetPadding( (int)DpToPixels(this.Context, Convert.ToSingle(5)), Control.PaddingTop, (int)DpToPixels(this.Context, Convert.ToSingle(5)), Control.PaddingBottom); //set image var editText = this.Control; if (!string.IsNullOrEmpty(element.Image)) { switch (element.ImageAlignment) { case ImageAlignment.Left: editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(element.Image), null, null, null); break; case ImageAlignment.Right: editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, GetDrawable(element.Image), null); break; } } editText.CompoundDrawablePadding = 5; //editText.SetMinHeight(30); Control.Background.SetColorFilter(element.BorderColor.ToAndroid(), PorterDuff.Mode.SrcAtop); }
/// <summary> /// Add some images to the given DB context. /// </summary> /// <param name="context">The DB context where entries will be added.</param> /// <param name="images">The set of images to add.</param> public static void AddImages(PeopleContext context, ResourceSet images) { if (images != null) { foreach (DictionaryEntry entry in images) { if (entry.Value is byte[] data) { string name = entry.Key.ToString(); ImageEntry imageEntry = new ImageEntry(); imageEntry.Id = name + ".png"; imageEntry.Data = data; switch (name) { case "world": imageEntry.PersonId = "1"; break; case "man_960_720": imageEntry.PersonId = "2"; break; case "mr_ed_960_720": imageEntry.PersonId = "7"; break; } context.ImageEntries.Add(imageEntry); } } } }
public PDFGeneration(SKImage image, ImageEntry imageEntry) { _resultImage = image; _imageEntry = imageEntry; // Initialize y offset, this will be used afterwards for y position in PDF content _yOffset = 0; }
public async Task <ImageEntry> AddImage(ImageEntry image) { await _context.UserImages.AddAsync(image); await _context.SaveChangesAsync(); return(image); }
/// <summary> /// Store an avatar image in the people DB. /// </summary> /// <param name="image">The avatar image to store.</param> /// <returns>Http bad request status if the image is empty, /// http conflict status if the person Id on the given image is not empty and /// does not match the person Id in the DB for the given image.</returns> protected IActionResult StoreAvatarImage(ImageEntry image) { if (image == null || image.Data == null || image.Data.Length == 0) { return(BadRequest(_localizer[Strings.EmptyImageData].Value)); } PersonEntry person = null; if (!string.IsNullOrWhiteSpace(image.PersonId)) { person = GetExistingPerson(image.PersonId); if (person == null) { return(BadRequest(_localizer[Strings.PersonIdNotFound, image.PersonId].Value)); } } lock (_contextLock) { ImageEntry existing = null; if (!string.IsNullOrWhiteSpace(image.Id)) { existing = GetExistingImage(image.Id); if (existing != null) { // updating an existing entry, make sure person ID in new image entry matches if (!string.IsNullOrWhiteSpace(existing.PersonId) && !existing.PersonId.Equals(image.PersonId)) { return(Conflict(_localizer[Strings.PersonIdMismatch].Value)); } } } if (existing == null) { // make sure a new Id is generated image.Id = null; _context.ImageEntries.Add(image); } else { existing.Data = image.Data; existing.PersonId = image.PersonId; _context.ImageEntries.Update(existing); } if (person != null) { person.AvatarId = image.Id; _context.PersonEntries.Update(person); } _context.SaveChanges(); return(Ok()); } }
public ActionResult AddImageEntry(ImageEntry data, int DiaryId) { EntryManager entry = new EntryManager(_context); data.Type = "Edit_Image_Entry"; data.ID = 0; entry.AddEntry(data, DiaryId); return(RedirectToAction("Show_Entry", new { ID = DiaryId })); }
//========= CONSTRUCTORS ========= #region Constructors /**<summary>Constructs the default palette image.</summary>*/ public PaletteImage() { this.pixels = new byte[1, 1]; this.entry = new ImageEntry(); this.entry.Flags = ImageFlags.DirectBitmap; this.entry.Width = 1; this.entry.Height = 1; this.entry.XOffset = 0; this.entry.YOffset = 0; }
/**<summary>Constructs a palette image with the specified dimensions.</summary>*/ public PaletteImage(Size size) { this.pixels = new byte[size.Width, size.Height]; this.entry = new ImageEntry(); this.entry.Flags = ImageFlags.DirectBitmap; this.entry.Width = (short)size.Width; this.entry.Height = (short)size.Height; this.entry.XOffset = 0; this.entry.YOffset = 0; }
/**<summary>Constructs a palette image with the specified dimensions and compression type.</summary>*/ public PaletteImage(int width, int height, int xOffset, int yOffset, ImageFlags compressionType) { this.pixels = new byte[width, height]; this.entry = new ImageEntry(); this.entry.Flags = compressionType; this.entry.Width = (short)width; this.entry.Height = (short)height; this.entry.XOffset = (short)xOffset; this.entry.YOffset = (short)yOffset; }
/**<summary>Constructs a palette image with the specified dimensions and compression type.</summary>*/ public PaletteImage(Size size, Point offset, ImageFlags compressionType) { this.pixels = new byte[size.Width, size.Height]; this.entry = new ImageEntry(); this.entry.Flags = compressionType; this.entry.Width = (short)size.Width; this.entry.Height = (short)size.Height; this.entry.XOffset = (short)offset.X; this.entry.YOffset = (short)offset.Y; }
public ImageEntry AddImage(string path) { lock (this.entries) { ImageEntry entry = new ImageEntry(path); this.entries.Add(entry); this.queueSema.Release(); CallUpdate(entry); return(entry); } }
/**<summary>Constructs a palette image with the specified dimensions.</summary>*/ public PaletteImage(int width, int height) { this.pixels = new byte[width, height]; this.entry = new ImageEntry(); this.entry.Flags = ImageFlags.DirectBitmap; this.entry.Width = (short)width; this.entry.Height = (short)height; this.entry.XOffset = 0; this.entry.YOffset = 0; }
protected virtual CompactRectangle Place(ImageEntry entry) { var source = GetBitmapFromZip(ZipStore, entry.ZipEntryIndex); Graphics.DrawImageUnscaled(source, entry.X + Padding, entry.Y + Padding); var rect = new CompactRectangle(entry.X + Padding, entry.Y + Padding, entry.Width - 2 * Padding, entry.Height - 2 * Padding); source.Dispose(); return(rect); }
private async void OnItemSelectedAsync(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem == null) { return; } ((ListView)sender).SelectedItem = null; ImageEntry imageEntry = (ImageEntry)e.SelectedItem; await Navigation.PushAsync(new CameraContentPage(imageEntry)); }
/**<summary>Constructs a palette with the specified colors and offset.</summary>*/ public Palette(Color[] colors, int offset) { this.colors = colors; entry = new ImageEntry(); entry.Flags = ImageFlags.PaletteEntries; entry.Width = (short)colors.Length; entry.Height = 0; entry.XOffset = (short)offset; entry.YOffset = 0; }
/**<summary>Constructs a palette with the specified number of colors and offset.</summary>*/ public Palette(int numColors, int offset) { colors = new Color[numColors]; entry = new ImageEntry(); entry.Flags = ImageFlags.PaletteEntries; entry.Width = (short)numColors; entry.Height = 0; entry.XOffset = (short)offset; entry.YOffset = 0; }
//========= CONSTRUCTORS ========= #region Constructors /**<summary>Constructs the default palette.</summary>*/ public Palette() { colors = new Color[1]; entry = new ImageEntry(); entry.Flags = ImageFlags.PaletteEntries; entry.Width = 1; entry.Height = 0; entry.XOffset = 0; entry.YOffset = 0; }
public static ImageEntry AddImage(string name, OpenRasta.Web.MediaType mediaType, MemoryStream data) { ImageEntry entry = new ImageEntry { Id = Images.Count, Name = name, MediaType = mediaType, Data = data }; Images.Add(entry); return entry; }
private static ImageEntry MakeImageEntry(Stream input) { using (var bitmap = (Bitmap)Bitmap.FromStream(input)) { var entry = new ImageEntry(); entry.imageWidth = (byte)(bitmap.Width == 256 ? 0 : bitmap.Width); entry.imageHeight = (byte)(bitmap.Height == 256 ? 0 : bitmap.Height); entry.palleteSize = 0; entry.reserved = 0; entry.colorPlanes = 1; entry.bitsPerPixel = (UInt16)Image.GetPixelFormatSize(bitmap.PixelFormat); entry.imageLength = (UInt32)input.Length; entry.offsetFromBoF = 0; // to be set elsewhere return entry; } }
private static void WriteImageEntry(Stream output, ImageEntry entry) { var bufSize = Marshal.SizeOf(typeof(ImageEntry)); var buf = new byte[bufSize]; var native = Marshal.AllocHGlobal(bufSize); try { Marshal.StructureToPtr(entry, native, false); Marshal.Copy(native, buf, 0, buf.Length); output.Write(buf, 0, buf.Length); } finally { Marshal.FreeHGlobal(native); } }
private void ParseLibImages() { ImageEntry img; while (_reader.BeginElement()) { if (_reader.Name.Equals("image", true)) { img = new ImageEntry(); while (_reader.ReadAttribute()) { if (_reader.Name.Equals("id", true)) img._id = (string)_reader.Value; else if (_reader.Name.Equals("name", true)) img._name = (string)_reader.Value; } while (_reader.BeginElement()) { img._path = null; if (_reader.Name.Equals("init_from", true)) { if (_v2 < 5) img._path = _reader.ReadElementString(); else while (_reader.BeginElement()) { if (_reader.Name.Equals("ref", true)) img._path = _reader.ReadElementString(); _reader.EndElement(); } } _reader.EndElement(); } _images.Add(img); } _reader.EndElement(); } }
public ImageEntry ToStoreEntry() { var entry = new ImageEntry { Image = new ImageIdentifier(this) { InstanceAvailability = "ONLINE", RetrieveAE = ServerDirectory.GetLocalServer(), SpecificCharacterSet = SpecificCharacterSet }, Data = new ImageEntryData { SourceAETitle = SourceAETitle } }; return entry; }
private void PopulatePartList(bool bRef, string path) { try { string[] files = Directory.GetFiles(path, "*.png", SearchOption.AllDirectories); int pathlen = path.Length; foreach (string it in files) { string substr = it.Substring(pathlen); ImageEntry thisEntry = null; foreach (ImageEntry entry in imageEntries) { if (entry.Name == substr) { thisEntry = entry; break; } } if (thisEntry == null) { thisEntry = new ImageEntry(); thisEntry.Name = substr; imageEntries.Add(thisEntry); } if (bRef) { thisEntry.bRefExists = true; } else { thisEntry.bTestExists = true; } } } catch (System.ArgumentException) { } catch (System.IO.DirectoryNotFoundException) { } catch (System.IO.FileNotFoundException) { } }
public IList<ImageEntry> GetImageEntries(ImageEntry criteria) { var sops = GetSopInstances(criteria); return sops.Select(s => s.ToStoreEntry()).ToList(); }
private IEnumerable<SopInstance> GetSopInstances(ImageEntry criteria) { try { string studyInstanceUid = null, seriesInstanceUid = null; if (criteria != null && criteria.Image != null) { studyInstanceUid = criteria.Image.StudyInstanceUid; seriesInstanceUid = criteria.Image.SeriesInstanceUid; } //This will throw when either Uid parameter is empty. var series = GetSeries(studyInstanceUid, seriesInstanceUid); if (series == null) return new List<SopInstance>(); //TODO (Marmot): make extended data queryable, too. var dicomCriteria = criteria.Image.ToDicomAttributeCollection(); var filters = new SopInstancePropertyFilters(dicomCriteria); var results = filters.FilterResults(series.GetSopInstances().Cast<SopInstance>()); return results; } catch (Exception e) { throw new Exception("An error occurred while performing the image query.", e); } }
public override ArcFile TryOpen(ArcView file) { if (!file.View.AsciiEqual (4, "PX10") || file.MaxOffset > uint.MaxValue) return null; int count = file.View.ReadInt32 (8); if (count <= 0 || count > 0xfffff) return null; uint index_size = file.View.ReadUInt32 (12); if (index_size > file.MaxOffset) return null; var encoding = Encodings.cp932.WithFatalFallback(); byte[] name_raw = new byte[12]; long dir_offset = 0x20; var dir = new List<Entry> (count); bool has_scripts = false; for (int i = 0; i < count; ++i) { file.View.Read (dir_offset, name_raw, 0, 12); int name_length = name_raw.Length; while (name_length > 0 && 0 == name_raw[name_length-1]) --name_length; if (0 == name_length) return null; string name = encoding.GetString (name_raw, 0, name_length).ToLowerInvariant(); Entry entry; if (name.EndsWith (".isf") || name.EndsWith (".snr")) { entry = new Entry { Name = name, Type = "script" }; has_scripts = true; } else if (name.EndsWith (".bin")) entry = new ImageEntry { Name = name }; else entry = FormatCatalog.Instance.Create<Entry> (name); entry.Offset = file.View.ReadUInt32 (dir_offset+12); entry.Size = file.View.ReadUInt32 (dir_offset+16); if (!entry.CheckPlacement (file.MaxOffset)) return null; dir.Add (entry); dir_offset += 0x14; } if (has_scripts) return new IsfArchive (file, this, dir); else return new ArcFile (file, this, dir); }
public System.Collections.Generic.IList<ImageIdentifier> ImageQuery(ImageIdentifier queryCriteria) { var criteria = new ImageEntry { Image = queryCriteria }; var result = Real.GetImageEntries(new GetImageEntriesRequest { Criteria = criteria }); return result.ImageEntries.Select(e => e.Image).ToList(); }