void Start() { loseText = loseState.GetComponent <TMPro.TMP_Text>(); loseImg = loseState.GetComponentInChildren <Image>(); cam = Camera.main; imgfx = cam.GetComponent <ImageEffect>(); playerScript = GetComponent <PlayerInputController>(); audioManager = FindObjectOfType <AudioManager>(); }
public static ImageEffect ChangeSprite(UI2DSprite ui, Sprite sprite) { EffectBuilder builder = new EffectBuilder(); ImageEffect e = builder.UI(ui) .TotalTime(0) .Init(() => { ui.sprite2D = sprite; }) .AnimateUpdate((aim, totaltime, nowtime) => { }) .Get(); return(e); }
public byte[] ProcessImage(byte[] data, int width, int height, ImageEffect imageEffect, int blurPixelSize) { ImageSetting imageSetting = new ImageSetting { Height = height, Width = width, BlurPixelSize = blurPixelSize, }; return(ImageProcess(data, imageEffect, imageSetting)); }
/// <summary> /// Find an ImageEffect by its name. /// </summary> /// <param name="effectName">The effect name</param> /// <returns>The ImageEffect with the specified name</returns> public ImageEffect FindEffectByName(string effectName) { ImageEffect effect = null; if (effects.ContainsKey(effectName)) { effect = effects[effectName]; } return(effect); }
private void ResetUpdateControls() { ResetControls(); if (rawImage == null || isBindingEnabled == false) return; var old = new ImageEffect(); old.Copy(EditionValue); History.Add(new HistoryObject(EffectType.Reset, EditionValue.GetCopy()) { oldValue = old }); UpdatePreview(true); }
// Use this for initialization void Start() { hp = maxHp; main = GetComponentInChildren <Camera>(); fpsc = GetComponent <RigidbodyFirstPersonController>(); imgE = GetComponentInChildren <ImageEffect>(); canGetDunked = true; gettingDunked = false; imgE.enabled = false; }
public static ImageEffect BlockClick(bool block) { EffectBuilder builder = new EffectBuilder(); ImageEffect e = builder.UI(null) .TotalTime(0) .Init(() => { click.SetActive(block); }) .Finish(() => { }) .AnimateUpdate((aim, totaltime, nowtime) => { }) .Get(); return(e); }
public void RemoveImageEffect(ImageEffect ie) { for (int i = 0; i < images.Count; i++) { CameraImageEffect effect = images[i]; if (effect.state == ie) { effect.Leave(this); images.Remove(effect); break; } } }
private byte[] ImageProcess(byte[] data, ImageEffect imageEffect, ImageSetting imageSetting) { try { using (MemoryStream StartMemoryStream = new MemoryStream()) { // write the string to the stream StartMemoryStream.Write(data, 0, data.Length); // create the start Bitmap from the MemoryStream that contains the image Bitmap startBitmap = new Bitmap(StartMemoryStream); Bitmap bitmap = ResizeImage(startBitmap, imageSetting.Width, imageSetting.Height); if (imageSetting.BlurPixelSize > 0) { bitmap = ImageBlur.Blur(bitmap, imageSetting.BlurPixelSize); } // Simulate effect switch (imageEffect.EffectType) { case Constants.ImageEffectType.None: //skip break; case Constants.ImageEffectType.Effect1: //apply effect 1. break; case Constants.ImageEffectType.Effect2: //apply effect 2. break; case Constants.ImageEffectType.Effect3: //apply effect 2. break; default: break; } return(ImageToByte(bitmap)); } } catch (Exception ex) { throw; } }
void Update() { value += state * Time.deltaTime; if (value <= 0f) { value = 0f; } else if (value >= 1f) { value = 1f; } ImageEffect.SetImageEffectMaterialIndex(effectIndex); ImageEffect.SetImageEffectValue(value); }
public static ImageEffect FadeOut(UI2DSprite sprite, float time) { EffectBuilder builder = new EffectBuilder(); ImageEffect e = builder.UI(sprite) .TotalTime(time) .Alpha(1) .AnimateUpdate((aim, totaltime, nowtime) => { if (nowtime < totaltime) { aim.alpha = Mathf.MoveTowards(aim.alpha, 0, 1 / totaltime * Time.fixedDeltaTime); } }).Get(); return(e); }
public void ImageFunction(Image _img, ImageEffect _effect) { if(!bFade) { bFade = true; _imgHold = _img; switch (_effect) { case ImageEffect.FADEINFADEOUT: StartCoroutine("Fade"); break; case ImageEffect.FLASHTOFADE: StartCoroutine("Flash"); break; } } }
private void CreatEffectOne() { if (imageNames.Count > 1) { creatNO++; creatNO = (int)Method.Warp(0, imageNames.Count, creatNO); } float offset = rand.Next(randArea) + offsetY; ImageEffect effect = new ImageEffect(imageNames[creatNO], entity.transform.Position + new Vector2(0, offset), aliveSecond); effect.size = size; imageEffects.Add(effect); imageEffects.RemoveAll(i => i.isDisappear); }
public static ImageEffect Move(UI2DSprite sprite, Vector3 origin, Vector3 final, float time) { EffectBuilder builder = new EffectBuilder(); ImageEffect e = builder.UI(sprite) .TotalTime(time) .Init(() => { sprite.transform.position = origin; }) .Finish(() => { sprite.transform.position = final; }) .AnimateUpdate((aim, totaltime, nowtime) => { if (nowtime < totaltime) { aim.alpha = Mathf.MoveTowards(aim.alpha, 1, 1 / totaltime * Time.fixedDeltaTime); } }).Get(); return(e); }
public static ImageEffect SetDefaultPostionByDepth(int depth, string pstr) { UI2DSprite ui = null; if (charaPanel.transform.Find("sprite" + depth) != null) { ui = charaPanel.transform.Find("sprite" + depth).GetComponent <UI2DSprite>(); } else { return(null); } float x; switch (pstr) { case "left": x = -320; break; case "middle": x = 0; break; case "right": x = 320; break; default: x = 0; break; } EffectBuilder builder = new EffectBuilder(); ImageEffect e = builder.UI(ui) .TotalTime(0) .Init(() => { ui.transform.localPosition = new Vector3(x, -360 + ui.height / 2); }) .AnimateUpdate((aim, totaltime, nowtime) => { }).Get(); return(e); }
public static ImageEffect SetDialog(bool open) { EffectBuilder builder = new EffectBuilder(); ImageEffect e = builder.UI(null) .TotalTime(0) .Init(() => { dialog.SetActive(open); dialog.GetComponent <UIWidget>().alpha = 0; //namelabel.text = ""; //dialoglabel.text = ""; //dialog.transform.Find("NextIcon_Sprite").gameObject.SetActive(false); }) .AnimateUpdate((aim, totaltime, nowtime) => { }) .Finish(() => { }) .Get(); return(e); }
public static ImageEffect Parallel(List <ImageEffect> effects) { ImageEffect effect = new ImageEffect(); List <float> times = new List <float>(); foreach (ImageEffect e in effects) { times.Add(e.time); } effect.time = times.Max(); effect.origin = null; effect.final = null; effect.loop = false; effect.init = () => { foreach (ImageEffect e in effects) { e.init(); } }; effect.finish = () => { foreach (ImageEffect e in effects) { e.finish(); } }; effect.update = (a, time, nowtime) => { foreach (ImageEffect e in effects) { if (nowtime < e.time) { e.update(e.aimUI, e.time, nowtime); } } }; return(effect); }
protected override void OnAttached() { try { var control = Control ?? Container; if (control is DependencyObject) { var image = control as Windows.UI.Xaml.Controls.Image; var uri = ImageEffect.GetText(Element); var bitmap = new BitmapImage(new Uri(uri)); bitmap.ImageOpened += Bitmap_ImageOpened; image.Source = bitmap; image.SizeChanged += Image_SizeChanged; } } catch (Exception ex) { Debug.WriteLine("Cannot set property on attached control. Error: ", ex.Message); } }
public static ImageEffect FadeInDialog(float time) { EffectBuilder builder = new EffectBuilder(); ImageEffect e = builder.UI(null) .TotalTime(time) .Init(() => { }) .AnimateUpdate((aim, totaltime, nowtime) => { if (nowtime < totaltime) { float t = Mathf.MoveTowards(dialog.GetComponent <UIWidget>().alpha, 1, 1 / totaltime * Time.fixedDeltaTime); dialog.GetComponent <UIWidget>().alpha = t; } }) .Finish(() => { dialog.GetComponent <UIWidget>().alpha = 1; }) .Get(); return(e); }
private CameraImageEffect AddImageEffect(ImageEffect ie) { CameraImageEffect effect = null; for (int i = 0; i < images.Count; i++) { if (images[i].state == ie) { effect = images[i]; break; } } if (effect == null) { effect = effects[(int)ie]; if (effect.Enter(this)) { images.Add(effect); } } return(effect); }
public static ImageEffect ChangeByDepth(int depth, Sprite sprite) { if (charaPanel.transform.Find("sprite" + depth) == null) { return(null); } else { EffectBuilder builder = new EffectBuilder(); UI2DSprite ui = charaPanel.transform.Find("sprite" + depth).GetComponent <UI2DSprite>(); ImageEffect e = builder.UI(ui) .TotalTime(0) .Init(() => { ui.sprite2D = sprite; ui.MakePixelPerfect(); }) .AnimateUpdate((aim, totaltime, nowtime) => { }) .Finish(() => { }) .Get(); return(e); } }
public static ImageEffect SetPostionByDepth(int depth, Vector3 position) { UI2DSprite ui = null; if (charaPanel.transform.Find("sprite" + depth) != null) { ui = charaPanel.transform.Find("sprite" + depth).GetComponent <UI2DSprite>(); } else { return(null); } EffectBuilder builder = new EffectBuilder(); ImageEffect e = builder.UI(ui) .TotalTime(0) .Init(() => { ui.transform.localPosition = position; }) .AnimateUpdate((aim, totaltime, nowtime) => { }).Get(); return(e); }
private void CreatEffectOne() { if (startPosition.X > endPosition.X) { return; } if (imageNames.Count > 1) { creatNO++; creatNO = (int)Method.Warp(0, imageNames.Count, creatNO); } float offset = rand.Next(randArea) + offsetY; ImageEffect effect = new ImageEffect(imageNames[creatNO], startPosition + new Vector2(0, offset), aliveSecond); imageEffects.Add(effect); aliveSecond -= creatTimer.GetLimitTime(); startPosition.X += ResouceManager.GetTextureWidth(imageNames[creatNO]) / 2; imageEffects.RemoveAll(i => i.isDisappear); }
public static ImageEffect DeleteSpriteByDepth(int depth) { if (charaPanel.transform.Find("sprite" + depth) == null) { return(null); } else { EffectBuilder builder = new EffectBuilder(); UI2DSprite ui = charaPanel.transform.Find("sprite" + depth).GetComponent <UI2DSprite>(); ImageEffect e = builder.UI(ui) .TotalTime(0) .Init(() => { //if (charaPanel.transform.Find("sprite" + depth) != null) //if(ui!=null) // GameObject.Destroy(ui.transform.gameObject); ui.sprite2D = null; }) .AnimateUpdate((aim, totaltime, nowtime) => { }) .Finish(() => { }) .Get(); return(e); } }
private void Update() { //if (Time.timeScale > 0f) { if (!animator.GetBool("isAttacking") && !animator.GetBool("isPushing") && !animator.GetBool("isThrowing")) // && !isDashing) { walkInput = new Vector2(Input.GetAxisRaw(walkHorizontalInput + inputExtensionString), Input.GetAxisRaw(walkVerticalInput + inputExtensionString)); /* * if (GameManager.singleGame) * { * if(walkInput.x == 0f) * walkInput.x = Input.GetAxisRaw(walkHorizontalInput + "2"); * if(walkInput.y == 0f) * walkInput.y = Input.GetAxisRaw(walkVerticalInput + "2"); * } */ if (walkInput.x != 0 && walkInput.y != 0) { walkInput /= 1.5f; } if (walkInput != Vector2.zero) { if (!isDashing) { speed = walkSpeed * (1 + (4 * timeSlowMoEffectValue)); } animator.SetBool("isWalking", true); if (walkInput.y < 0) { animator.SetInteger("direction", 2); if (prevWalkState == 0) { comboKeys += "D"; } } else if (walkInput.y > 0) { animator.SetInteger("direction", 0); if (prevWalkState == 0) { comboKeys += "U"; } } else if (walkInput.x > 0) { animator.SetInteger("direction", 1); if (prevWalkState == 0) { comboKeys += "R"; } } else if (walkInput.x < 0) { animator.SetInteger("direction", 3); if (prevWalkState == 0) { comboKeys += "L"; } } if (walkInput.x > 0) { sprRenderer.flipX = true; } else { sprRenderer.flipX = false; } } else { speed = 0f; animator.SetBool("isWalking", false); } } //Potion if (Input.GetButtonDown(attackInput + inputExtensionString)) { potionTimer = potionAttackButtonPressMinTime; } if (Input.GetButtonUp(attackInput + inputExtensionString)) { potionTimer = -1000f; } if (potionTimer <= 0 && potionTimer > -900f) { EquipmentManager eqMan = GetComponent <EquipmentManager>(); if (eqMan != null && eqMan.GetCurrentEquipment() != null && eqMan.GetCurrentEquipment().Length > 1 && eqMan.GetCurrentEquipment()[1] != null) { eqMan.UsePotion(GetComponent <EquipmentManager>().GetCurrentEquipment()[1]); if (playerNo == 1) { Subtitles.AddPlayer1Subtitle("Potion Used"); } else if (playerNo == 2) { Subtitles.AddPlayer2Subtitle("Potion Used"); } } else { if (playerNo == 1) { Subtitles.AddPlayer1Subtitle("Potion not equipped"); } else if (playerNo == 2) { Subtitles.AddPlayer2Subtitle("Potion not equipped"); } } potionTimer = -1000f; potionUsed = true; } else if (potionTimer > 0f && potionTimer > -900f) { potionTimer -= Time.deltaTime; } //Attack if (actionPoints >= attackActionDeplete && !animator.GetBool("isAttacking") && !animator.GetBool("isPushing") && !animator.GetBool("isThrowing") && !isDashing && (Input.GetButtonUp(attackInput + inputExtensionString) /*|| GameManager.singleGame && Input.GetButtonDown(attackInput + "2")*/)) { if (!potionUsed) { comboKeys += "A"; if (comboKeys != "UA" && comboKeys != "RA" && comboKeys != "DA" && comboKeys != "LA") { animator.SetBool("isAttacking", true); speed = attackSpeed * (1 + (4 * timeSlowMoEffectValue)); /* * if (playerNo == 1) * Subtitles.AddPlayer1Subtitle("TEST_Player 1 Attacking"); * else if (playerNo == 2) * Subtitles.AddPlayer2Subtitle("TEST_Player 2 Attacking"); */ if (animator.GetBool("isWalking")) { attackSpeedTimer = attackSpeedTime; } else { int dir = animator.GetInteger("direction"); if (dir == 0) { walkInput.x = 0; walkInput.y = 1; } else if (dir == 1) { walkInput.x = 1; walkInput.y = 0; } else if (dir == 2) { walkInput.x = 0; walkInput.y = -1; } else if (dir == 3) { walkInput.x = -1; walkInput.y = 0; } attackSpeedTimer = attackSpeedTime / 2f; } actionPoints -= attackActionDeplete; if (aud != null && TogglesValues.sound) { aud.PlayOneShot(weaponSounds[weaponPossession.weaponID + 1], weaponSoundVolumes[weaponPossession.weaponID + 1]); } } } potionUsed = false; } //Push if (pushPossible != null && !animator.GetBool("isPushing") && !animator.GetBool("isAttacking") && !animator.GetBool("isThrowing") && !isDashing && (comboKeys == "UU" || comboKeys == "RR" || comboKeys == "DD" || comboKeys == "LL")) { animator.SetBool("isPushing", true); speed = 0f; if (playerNo == 1) { Subtitles.AddPlayer1Subtitle("TEST_Player 1 Pushing"); } else if (playerNo == 2) { Subtitles.AddPlayer2Subtitle("TEST_Player 2 Pushing"); } actionPoints -= pushActionDeplete; pushPossible = null; comboKeys = ""; } //Dash if (actionPoints >= dashActionDeplete && !isDashing && !animator.GetBool("isAttacking") && !animator.GetBool("isPushing") && !animator.GetBool("isThrowing") && (comboKeys == "UU" || comboKeys == "RR" || comboKeys == "DD" || comboKeys == "LL" || comboKeys == "UR" || comboKeys == "UL" || comboKeys == "DR" || comboKeys == "DL" || comboKeys == "RU" || comboKeys == "RD" || comboKeys == "LU" || comboKeys == "LD") && hitCheck.knockback == Vector2.zero) { isDashing = true; dashTimer = dashTime / (1 + (4 * timeSlowMoEffectValue)); speed = dashSpeed * (1 + (4 * timeSlowMoEffectValue)); gameObject.layer = 10; actionPoints -= dashActionDeplete; if (aud != null && TogglesValues.sound) { aud.PlayOneShot(dashSound); } comboKeys = ""; } //Throw if (!animator.GetBool("isThrowing") && !animator.GetBool("isAttacking") && !animator.GetBool("isPushing") && !isDashing && (((keyComboTimer <= keyComboMaxTimeGap / 3.8f) && (comboKeys == "UA" || comboKeys == "RA" || comboKeys == "DA" || comboKeys == "LA")) || ((Input.GetButtonDown(attackInput + inputExtensionString)) && (Input.GetButtonDown(walkHorizontalInput + inputExtensionString) || Input.GetButtonDown(walkVerticalInput + inputExtensionString)))) ) { animator.SetBool("isThrowing", true); speed = attackSpeed * (1 + (4 * timeSlowMoEffectValue)); attackSpeedTimer = attackSpeedTime / 2f; actionPoints -= throwActionDeplete; if (throwFXObject && nextFXdelay < 0f) { GameObject FX = Instantiate(throwFXObject, transform.position, Quaternion.Euler(0f, 0f, 0f)); nextFXdelay = MINIMUM_TIME_BETWEEN_FX; } comboKeys = ""; } if (actionPoints < 1f) { actionPoints += regenerateActionPointsPerSec * Time.deltaTime * (1 + (4 * timeSlowMoEffectValue)); } if (isDashing && dashTimer <= 0f) { isDashing = false; speed = walkSpeed * (1 + (4 * timeSlowMoEffectValue)); gameObject.layer = 8; } else if (dashTimer > 0f || (attackSpeedTimer > 0f && attackSpeedTimer < attackSpeedTime / 3f)) { GameObject ghostSpriteFX = Instantiate(dashFXObject, transform.position, Quaternion.Euler(0f, 0f, 0f)); SpriteRenderer GSFX_sprRend = ghostSpriteFX.GetComponent <SpriteRenderer>(); if (dashFXObject && nextFXdelay < 0f) { GameObject FX = Instantiate(dashFXObject, transform.position, Quaternion.Euler(0f, 0f, 0f)); FX.GetComponent <SpriteRenderer>().sprite = sprRenderer.sprite; nextFXdelay = MINIMUM_TIME_BETWEEN_FX; } GSFX_sprRend.sprite = sprRenderer.sprite; if (name == "Player1") { GSFX_sprRend.color = Color.red; GSFX_sprRend.material.color = Color.red; } else { GSFX_sprRend.color = Color.green; GSFX_sprRend.material.color = Color.green; } } if ((animator.GetBool("isAttacking") || animator.GetBool("isThrowing")) && attackSpeedTimer <= 0f) { speed = 0f; } if (keyComboTimer >= keyComboMaxTimeGap) { comboKeys = ""; } if (comboKeys != "") { keyComboTimer += Time.deltaTime; } else { keyComboTimer = 0f; } if (hitComboTimer <= 0f) { hitComboCount = 0; } else { hitComboTimer -= Time.deltaTime; } if (criticalHitTimePauseTimer <= 0f) { if (Time.timeScale >= 0.05f && Time.timeScale <= 0.1f) { Time.timeScale = 1f; } else if (timeSlowMoTimer > 0f) { timeSlowMoTimer -= Time.unscaledDeltaTime; Time.timeScale = Mathf.Lerp(Time.timeScale, 0.5f, 0.025f); ImageEffect.SetImageEffectMaterialIndex(2); timeSlowMoEffectValue = Mathf.Lerp(timeSlowMoEffectValue, 0.25f, 0.025f); ImageEffect.SetImageEffectValue(timeSlowMoEffectValue); } else if (timeSlowMoTimer <= 0f) { if (Time.timeScale >= 0.5f && Time.timeScale != 1f) { if (Time.timeScale <= 0.505f && aud != null && TogglesValues.sound) { aud.PlayOneShot(slowMoToNormalSound); } Time.timeScale = Mathf.Lerp(Time.timeScale, 1f, 0.05f); if (Time.timeScale >= 0.98f) { Time.timeScale = 1f; } } if (timeSlowMoEffectValue <= 0f) { ImageEffect.SetImageEffectMaterialIndex(0); ImageEffect.SetImageEffectValue(0.04f); timeSlowMoEffectValue = 0f; } else { timeSlowMoEffectValue -= Time.unscaledDeltaTime / 5f; ImageEffect.SetImageEffectValue(timeSlowMoEffectValue); } } } else { Time.timeScale = 0.06f; criticalHitTimePauseTimer -= Time.unscaledDeltaTime; } animator.speed = 1f * (1 + (4 * timeSlowMoEffectValue)); attackSpeedTimer -= Time.deltaTime; dashTimer -= Time.deltaTime; nextFXdelay -= Time.deltaTime; // don't spam FX every frame prevWalkState = walkInput == Vector2.zero ? 0 : 1; } }
public EffectItem(ImageEffect imageEffect, string effectName) { _imageEffect = imageEffect; _effectName = effectName; }
void UpdateImageSource(ImageEffect imageEffect) { // some effects can change pixels outside the bounds of the source // image, so we need a margin to make those pixels visible var targetOffset = new Point2F(_marginLT, _marginLT); int w = _bitmap.PixelWidth + _marginLT + _marginRB; int h = _bitmap.PixelHeight + _marginLT + _marginRB; // the render target object var rt = _d2dContext; // create the target Direct2D bitmap var bpTarget = new D2D.BitmapProperties1( new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied), (float)_bitmap.DpiX, (float)_bitmap.DpiY, D2D.BitmapOptions.Target | D2D.BitmapOptions.CannotDraw); var targetBmp = D2D.Bitmap1.Create(rt, new Size2L(w, h), bpTarget); // associate the target bitmap with render target rt.SetTarget(targetBmp); // start drawing rt.BeginDraw(); // clear the target bitmap rt.Clear(null); // convert C1Bitmap image to Direct2D image var d2dBitmap = _bitmap.ToD2DBitmap1(rt, D2D.BitmapOptions.None); // apply the effect or just draw the original image switch (imageEffect) { case ImageEffect.Original: rt.DrawImage(d2dBitmap, targetOffset); break; case ImageEffect.GaussianBlur: rt.DrawImage(ApplyGaussianBlur(d2dBitmap), targetOffset); break; case ImageEffect.Sharpen: rt.DrawImage(ApplySharpen(d2dBitmap), targetOffset); break; case ImageEffect.HorizontalSmear: rt.DrawImage(ApplyHorizontalSmear(d2dBitmap), targetOffset); break; case ImageEffect.Shadow: rt.DrawImage(ApplyShadow(d2dBitmap), targetOffset); break; case ImageEffect.DisplacementMap: rt.DrawImage(ApplyDisplacementMap(d2dBitmap), targetOffset); break; case ImageEffect.Emboss: rt.DrawImage(ApplyEmboss(d2dBitmap), targetOffset); break; case ImageEffect.EdgeDetect: rt.DrawImage(ApplyEdgeDetect(d2dBitmap), targetOffset); break; case ImageEffect.Sepia: rt.DrawImage(ApplySepia(d2dBitmap), targetOffset); break; } d2dBitmap.Dispose(); // draw the text label in case of the Shadow effect if (imageEffect == ImageEffect.Shadow) { var mr = Matrix3x2.Rotation(-90f); var mt = Matrix3x2.Translation(targetOffset.X + 6f, targetOffset.Y + 344f); rt.Transform = mr * mt; _brush.SetColor(ColorF.White); rt.DrawTextLayout(new Point2F(-1f, -1f), _textLayout, _brush); _brush.SetColor(ColorF.DimGray); rt.DrawTextLayout(Point2F.Empty, _textLayout, _brush); rt.Transform = Matrix3x2.Identity; } // finish drawing (all drawing commands are executed at that moment) if (!rt.EndDraw(true)) { targetBmp.Dispose(); // try to recreate the device resources if the old GPU device was removed DiscardDeviceResources(); CreateDeviceResources(); return; } // detach the target bitmap rt.SetTarget(null); // create a temporary C1Bitmap object var outBitmap = new C1Bitmap(_bitmap.ImagingFactory); // import the image from Direct2D target bitmap to C1Bitmap outBitmap.Import(targetBmp, rt, new RectL(w, h)); targetBmp.Dispose(); // convert C1Bitmap to a System.Drawing.Bitmap ClearGdiBitmap(); _lastGdiBitmap = outBitmap.ToGdiBitmap(); outBitmap.Dispose(); // show the result in the PictureBox pictureBox1.Image = _lastGdiBitmap; }
/// <summary> /// Creates the process arguments. /// </summary> /// <returns>The string that represents the process arguments.</returns> public virtual string CreateProcessArguments() { var sb = new StringBuilder(); sb.Append("-o -"); // output to standard output as opposed to a file. sb.Append($" -t {(CaptureTimeoutMilliseconds < 0 ? "0" : CaptureTimeoutMilliseconds.ToString(Ci))}"); // Basic Width and height if (CaptureWidth > 0 && CaptureHeight > 0) { sb.Append($" -w {CaptureWidth.ToString(Ci)}"); sb.Append($" -h {CaptureHeight.ToString(Ci)}"); } // Display Preview if (CaptureDisplayPreview) { if (CaptureDisplayPreviewInFullScreen) { sb.Append(" -f"); } if (CaptureDisplayPreviewOpacity != byte.MaxValue) { sb.Append($" -op {CaptureDisplayPreviewOpacity.ToString(Ci)}"); } } else { sb.Append(" -n"); // no preview } // Picture Settings if (ImageSharpness != 0) { sb.Append($" -sh {ImageSharpness.Clamp(-100, 100).ToString(Ci)}"); } if (ImageContrast != 0) { sb.Append($" -co {ImageContrast.Clamp(-100, 100).ToString(Ci)}"); } if (ImageBrightness != 50) { sb.Append($" -br {ImageBrightness.Clamp(0, 100).ToString(Ci)}"); } if (ImageSaturation != 0) { sb.Append($" -sa {ImageSaturation.Clamp(-100, 100).ToString(Ci)}"); } if (ImageIso >= 100) { sb.Append($" -ISO {ImageIso.Clamp(100, 800).ToString(Ci)}"); } if (CaptureVideoStabilizationEnabled) { sb.Append(" -vs"); } if (CaptureExposureCompensation != 0) { sb.Append($" -ev {CaptureExposureCompensation.Clamp(-10, 10).ToString(Ci)}"); } if (CaptureExposure != CameraExposureMode.Auto) { sb.Append($" -ex {CaptureExposure.ToString().ToLowerInvariant()}"); } if (CaptureWhiteBalanceControl != CameraWhiteBalanceMode.Auto) { sb.Append($" -awb {CaptureWhiteBalanceControl.ToString().ToLowerInvariant()}"); } if (ImageEffect != CameraImageEffect.None) { sb.Append($" -ifx {ImageEffect.ToString().ToLowerInvariant()}"); } if (ImageColorEffectU >= 0 && ImageColorEffectV >= 0) { sb.Append( $" -cfx {ImageColorEffectU.Clamp(0, 255).ToString(Ci)}:{ImageColorEffectV.Clamp(0, 255).ToString(Ci)}"); } if (CaptureMeteringMode != CameraMeteringMode.Average) { sb.Append($" -mm {CaptureMeteringMode.ToString().ToLowerInvariant()}"); } if (ImageRotation != CameraImageRotation.None) { sb.Append($" -rot {((int)ImageRotation).ToString(Ci)}"); } if (ImageFlipHorizontally) { sb.Append(" -hf"); } if (ImageFlipVertically) { sb.Append(" -vf"); } if (CaptureSensorRoi.IsDefault == false) { sb.Append($" -roi {CaptureSensorRoi}"); } if (CaptureShutterSpeedMicroseconds > 0) { sb.Append($" -ss {CaptureShutterSpeedMicroseconds.Clamp(0, 6000000).ToString(Ci)}"); } if (CaptureDynamicRangeCompensation != CameraDynamicRangeCompensation.Off) { sb.Append($" -drc {CaptureDynamicRangeCompensation.ToString().ToLowerInvariant()}"); } if (CaptureWhiteBalanceControl == CameraWhiteBalanceMode.Off && (CaptureWhiteBalanceGainBlue != 0M || CaptureWhiteBalanceGainRed != 0M)) { sb.Append($" -awbg {CaptureWhiteBalanceGainBlue.ToString(Ci)},{CaptureWhiteBalanceGainRed.ToString(Ci)}"); } if (ImageAnnotationFontSize > 0) { sb.Append($" -ae {ImageAnnotationFontSize.Clamp(6, 160).ToString(Ci)}"); sb.Append($",{(ImageAnnotationFontColor == null ? "0xff" : ImageAnnotationFontColor.ToYuvHex(true))}"); if (ImageAnnotationBackground != null) { ImageAnnotations |= CameraAnnotation.SolidBackground; sb.Append($",{ImageAnnotationBackground.ToYuvHex(true)}"); } } if (ImageAnnotations != CameraAnnotation.None) { sb.Append($" -a {((int)ImageAnnotations).ToString(Ci)}"); } if (string.IsNullOrWhiteSpace(ImageAnnotationsText) == false) { sb.Append($" -a \"{ImageAnnotationsText.Replace("\"", "'")}\""); } return(sb.ToString()); }
public static byte[] ImageProcess(ImageModel image, ImageEffect imageEffect) { }
/// <summary> /// Draws the image on SurfaceImageSource. /// </summary> void UpdateImageSource(ImageEffect imageEffect) { int w = _bitmap.PixelWidth + _marginLT + _marginRB; int h = _bitmap.PixelHeight + _marginLT + _marginRB; Point2L surfaceOffset = Point2L.Empty; DXGI.Surface dxgiSurface = null; var hr = HResult.Ok; // receive the target DXGI.Surface and offset for drawing for (int i = 0; i <= 1; i++) { hr = _sisNative.BeginDraw(new RectL(w, h), out surfaceOffset, out dxgiSurface); if ((hr != DXGI.ResultCode.DeviceRemoved && hr != DXGI.ResultCode.DeviceReset) || i > 0) { break; } // try to recreate the device resources if the old GPU device was removed DiscardDeviceResources(); CreateDeviceResources(); _sisNative.SetDevice(_dxgiDevice); } hr.CheckError(); // the render target object var rt = _d2dContext; // create the target Direct2D bitmap for the given DXGI.Surface var bpTarget = new D2D.BitmapProperties1( new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied), (float)_bitmap.DpiX, (float)_bitmap.DpiY, D2D.BitmapOptions.Target | D2D.BitmapOptions.CannotDraw); var targetBmp = D2D.Bitmap1.Create(rt, dxgiSurface, bpTarget); dxgiSurface.Dispose(); // associate the target bitmap with render target rt.SetTarget(targetBmp); targetBmp.Dispose(); // start drawing rt.BeginDraw(); // clear the target bitmap rt.Clear(null); // convert C1Bitmap image to Direct2D image var d2dBitmap = _bitmap.ToD2DBitmap1(rt, D2D.BitmapOptions.None); // apply the effect or just draw the original image surfaceOffset.X += _marginLT; surfaceOffset.Y += _marginLT; var targetOffset = surfaceOffset.ToPoint2F(); switch (imageEffect) { case ImageEffect.Original: rt.DrawImage(d2dBitmap, targetOffset); break; case ImageEffect.GaussianBlur: rt.DrawImage(ApplyGaussianBlur(d2dBitmap), targetOffset); break; case ImageEffect.Sharpen: rt.DrawImage(ApplySharpen(d2dBitmap), targetOffset); break; case ImageEffect.HorizontalSmear: rt.DrawImage(ApplyHorizontalSmear(d2dBitmap), targetOffset); break; case ImageEffect.Shadow: rt.DrawImage(ApplyShadow(d2dBitmap), targetOffset); break; case ImageEffect.DisplacementMap: rt.DrawImage(ApplyDisplacementMap(d2dBitmap), targetOffset); break; case ImageEffect.Emboss: rt.DrawImage(ApplyEmboss(d2dBitmap), targetOffset); break; case ImageEffect.EdgeDetect: rt.DrawImage(ApplyEdgeDetect(d2dBitmap), targetOffset); break; case ImageEffect.Sepia: rt.DrawImage(ApplySepia(d2dBitmap), targetOffset); break; } d2dBitmap.Dispose(); // draw the additional text label in case of the Shadow effect if (imageEffect == ImageEffect.Shadow) { var mr = Matrix3x2.Rotation(-90f); var mt = Matrix3x2.Translation(targetOffset.X + 6f, targetOffset.Y + 344f); rt.Transform = mr * mt; _brush.SetColor(ColorF.White); rt.DrawTextLayout(new Point2F(-1f, -1f), _textLayout, _brush); _brush.SetColor(ColorF.DimGray); rt.DrawTextLayout(Point2F.Empty, _textLayout, _brush); rt.Transform = Matrix3x2.Identity; } // finish drawing (all drawing commands are executed at that moment) rt.EndDraw(); // detach and actually dispose the target bitmap rt.SetTarget(null); // complete drawing on SurfaceImageSource _sisNative.EndDraw(); }
//Apply the change over the image preview private SoftwareBitmap ApplyImageEffect8bitsNoHistoAsync(ImageComponent<ushort> image, ImageEffect edition) { SoftwareBitmap bitmap = CreateBitmap(BitmapPixelFormat.Bgra8, edition.Rotation, image.dim); edition.ApplyTo8Bits(image, bitmap, false); return bitmap; }