internal static void UpdateImage( FrameHolder frameHolder, IEditable itemsBase, Pixel[,] pixels, ImageEditor imageEditor) { BitmapData data = frameHolder.Image.LockBits( new Rectangle(0, 0, frameHolder.Image.Width, frameHolder.Image.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int stride = data.Stride; unsafe { for (int i = 0; i < itemsBase.FrameSize.FrameWidth; i++) { for (int j = 0; j < itemsBase.FrameSize.FrameHeight; j++) { Color col = PixelHelper.PixelColor(pixels[i, j]); if (frameHolder.Color[i, j] != col) { frameHolder.PreviewImage.SetPixel(i, j, col); frameHolder.Color[i, j] = col; imageEditor.DrawScaledPixel(i, j, col); } } } } frameHolder.Image.UnlockBits(data); }
private IEnumerator Setup() { yield return(new WaitForFixedUpdate()); if (this.fakeShadowPrefab != null && this.spriteRenderer != null) { float widthOffset = PixelHelper.CovertPixelsToUnits(this.widthOffsetInPixels); Vector3 position = new Vector3(this.transform.position.x - widthOffset, this.spriteRenderer.bounds.min.y, this.spriteRenderer.bounds.min.z); float shadowWidth = this.spriteRenderer.sprite.bounds.size.x + widthOffset; GameObject shadowObject = Instantiate(this.fakeShadowPrefab, position, this.transform.rotation, this.transform); shadowObject.transform.localScale = new Vector3(shadowWidth, this.transform.localScale.y, this.transform.localScale.z); } }
public PixelSet LoadImage(string filename) { Image loadImage = Image.FromFile(filename); Bitmap bitmap = new Bitmap(loadImage); PixelSet pixelSet = new PixelSet(loadImage.Width, loadImage.Height); for (int i = 0; i < loadImage.Width - 1; i++) { for (int j = 0; j < loadImage.Height - 1; j++) { pixelSet.Pixels[i, j] = PixelHelper.Create(bitmap.GetPixel(i, j)); } } return(pixelSet); }
private void PickColorFromColorImage(Point localMousePosition) { Bitmap image = new Bitmap(ColorImage.Image); try { Color col = image.GetPixel(localMousePosition.X, localMousePosition.Y); _colorSelection.CurrentColor = PixelHelper.Create(col); } catch { // fail safe int i = 0; i++;; } }
public WriteableBitmap ConvertToWriteableBitmap() { var writeableBitmap = new WriteableBitmap(Width, Height); using (BitmapContext context = writeableBitmap.GetBitmapContext()) { for (int x = 0; x < Width; ++x) { for (int y = 0; y < Height; ++y) { PixelHelper.SetPixel(context, x, y, Bitmap[x, y]); } } } return(writeableBitmap); }
private Bitmap CreateImage(PixelSet pixelSet) { Pixel[,] pixels = pixelSet.Pixels; Bitmap previewImage = new Bitmap(pixelSet.Width, pixelSet.Height); for (int i = 0; i < pixelSet.Width - 1; i++) { for (int j = 0; j < pixelSet.Height - 1; j++) { Color col = PixelHelper.PixelColor(pixels[i, j]); previewImage.SetPixel(i, j, col); } } return(previewImage); }
private void RedrawColorPreview() { Color borderColor = Color.Red; for (int i = 0; i < TotalColors; i++) { Color color = PixelHelper.PixelColor(_pixels[i]); for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { _colors.SetPixel(x + (i * 20) + 2, y + 2, color); } } } ColorPreviewImage.Image = _colors; }
/// <summary> /// The gun always rotates on the pivot of the gun sprite. /// But depending on how close the mouse cursor is to the character, or the gun barrel, it gets the rotation angle either from the tip of the gun barrel, or the center of the character sprite /// When the cursor is far away it get the radius from the gun barrel. /// But if the cursor is getting to close, the radius changes to the center of the character /// This is prevent the gun for wobbling, and not to aim backwards (shoots left, but is looking right). /// </summary> private void SetRotation() { if (this.spriteRenderer.sprite == null) { return; } float gunBarrelOffsetLocal = PixelHelper.CovertPixelsToUnits(this.gunBarrelYCenterPositionInPixels); Vector2 gunBarrelLocalPosition = new Vector2(this.spriteRenderer.sprite.bounds.max.x, this.spriteRenderer.sprite.bounds.max.y + gunBarrelOffsetLocal / 2); Vector2 gunBarrelWorldPosition = (Vector2)this.transform.TransformPoint(this.transform.localPosition + (Vector3)gunBarrelLocalPosition); Vector2 mouseToCharacterRadius = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition) - (Vector2)this.transform.parent.position; Vector2 mouseToGunRadius = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition) - (Vector2)gunBarrelWorldPosition; Vector2 characterToGunRadius = (Vector2)this.transform.parent.position - gunBarrelWorldPosition; Vector2 radius = Vector3.Distance(characterToGunRadius, mouseToGunRadius) > Vector3.Distance(gunBarrelWorldPosition, this.transform.parent.position) * 2 ? mouseToGunRadius : mouseToCharacterRadius; this.Rotate(radius); }
/// <summary> /// This method calculates and finds the position of the gun barrel (top right of the weapon sprite). /// </summary> private void SpawnProjectile() { if (!this.HasSprite()) { return; } float gunBarrelOffsetLocal = PixelHelper.CovertPixelsToUnits(this.gunBarrelYCenterPositionInPixels); Vector2 gunBarrelLocalPosition = new Vector2(this.spriteRenderer.sprite.bounds.max.x, this.spriteRenderer.sprite.bounds.max.y + gunBarrelOffsetLocal / 2); GameObject projectile = Instantiate(this.projectilePrefab, this.transform.position, this.transform.rotation, transform); Vector2 projectileSize = projectile.GetComponent <SpriteRenderer>().sprite.bounds.size; // Sets the position of the projectile, relative to the parent (gun) projectile.transform.localPosition = (Vector2)(gunBarrelLocalPosition - projectileSize / 2); projectile.transform.SetParent(null); this.TrySpawnMuzzleFlash(gunBarrelLocalPosition, projectileSize); }
void InitializeView() { var relativeLayout = new RelativeLayout(this); relativeLayout.LayoutParameters = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent ); int nextID = 100; var density = this.Resources.DisplayMetrics.Density; _backgroundImageView = new ImageView(this); var backgroundLayout = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent ); _backgroundImageView.LayoutParameters = backgroundLayout; _backgroundImageView.SetBackgroundColor(Color.LightGray); relativeLayout.AddView(_backgroundImageView); _lowAndHighTemperatureLabel = new TextView(this); _lowAndHighTemperatureLabel.Id = nextID++; _lowAndHighTemperatureLabel.SetTextSize(ComplexUnitType.Dip, 20f); _lowAndHighTemperatureLabel.SetPadding( PixelHelper.DpToPixels(10, density), 0, 0, PixelHelper.DpToPixels(60, density) ); _lowAndHighTemperatureLabel.SetTextColor(Color.White); var lowAndHighTemperatureLayout = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent ); lowAndHighTemperatureLayout.AddRule(LayoutRules.AlignParentBottom); _lowAndHighTemperatureLabel.LayoutParameters = lowAndHighTemperatureLayout; relativeLayout.AddView(_lowAndHighTemperatureLabel); _currentTemperatureLabel = new TextView(this); _currentTemperatureLabel.Id = nextID++; _currentTemperatureLabel.SetTextSize(ComplexUnitType.Dip, 50f); _currentTemperatureLabel.SetPadding( PixelHelper.DpToPixels(10, density), 0, 0, 0 ); _currentTemperatureLabel.SetTextColor(Color.White); var currentTemperatureLayout = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent ); currentTemperatureLayout.AddRule(LayoutRules.Above, _lowAndHighTemperatureLabel.Id); _currentTemperatureLabel.LayoutParameters = currentTemperatureLayout; relativeLayout.AddView(_currentTemperatureLabel); _descriptionLabel = new TextView(this); _descriptionLabel.Id = nextID++; _descriptionLabel.SetTextSize(ComplexUnitType.Dip, 20f); _descriptionLabel.SetPadding( PixelHelper.DpToPixels(10, density), 0, 0, 0 ); _descriptionLabel.SetTextColor(Color.White); var descriptionLayout = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent ); descriptionLayout.AddRule(LayoutRules.Above, _currentTemperatureLabel.Id); _descriptionLabel.LayoutParameters = descriptionLayout; relativeLayout.AddView(_descriptionLabel); SetContentView(relativeLayout); }
private void DoSharpOnce() { PixelHelper.Sharp(_originalDicomImage.Width, _originalDicomImage.Height, _image.Pixels); _image.Render(0, _flipX, false, _rotationAngle); Image = _image.AsWriteableBitmap(); }