public Color GetPixel(int x, int y) { if (bmprep == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Cannot get pixel data for this type of bitmap ({0})", rep.GetType())); } return(bmprep.ColorAt(x, y).ToEto()); }
public override Xwt.Drawing.Color GetBitmapPixel(object handle, int x, int y) { NSImage img = (NSImage)handle; NSBitmapImageRep bitmap = img.Representations().OfType <NSBitmapImageRep> ().FirstOrDefault(); if (bitmap != null) { return(bitmap.ColorAt(x, y).ToXwtColor()); } else { throw new InvalidOperationException("Not a bitmnap image"); } }
public void PlayNewImageInScale(NSImage image, Scale scale) { ForceStop = false; if (image.Size.Width > 150 || image.Size.Height > 150) { image = ImageHelpers.ResizeImage(image, new CGSize(150, 150)); } PlayerNode.Play(); using (var imageRepresentation = new NSBitmapImageRep(image.AsTiff())) { var imageSize = image.Size; for (var x = 0; x < imageSize.Width; x++) { for (var y = 0; y < imageSize.Height; y++) { if (ForceStop) { return; } var color = imageRepresentation.ColorAt(x, y); var carrierFrequency = GetCarrierFrequencyForColor(color); var modulatorFrequency = GetModulatorFrequencyForColor(color); var sampleLength = GetNoteLengthForColor(color); var octave = GetOctaveForColor(color); var pan = GetPanForColor(color); var closestOctave = FrequenciesByOctave.Keys.Aggregate((a, b) => Math.Abs(a - octave) < Math.Abs(b - octave) ? a : b); var closestCarrier = ScaleHelper.GetNotesForScale(scale, closestOctave).Aggregate( (a, b) => Math.Abs(a - carrierFrequency) < Math.Abs(b - carrierFrequency) ? a : b); var closestModulator = ScaleHelper.GetNotesForScale(scale, closestOctave).Aggregate( (a, b) => Math.Abs(a - modulatorFrequency) < Math.Abs(b - modulatorFrequency) ? a : b); PlayToneForColor(closestCarrier, closestModulator, sampleLength, pan, color); } } } }
public Color GetPixel(int x, int y) { EnsureRep(); if (bmprep == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Cannot get pixel data for this type of bitmap ({0})", rep?.GetType())); } // don't convert colorspace here otherwise we get incorrect data.. why? var nscolor = bmprep.ColorAt(x, y); if (nscolor.ComponentCount >= 3) { nscolor.GetRgba(out var red, out var green, out var blue, out var alpha); return(new Color(nscolor, (float)red, (float)green, (float)blue, (float)alpha)); } return(nscolor.ToEto()); }