public ImageSprite(Texture2D texture, ImageSourceId sourceId) { image = new Image(); var source = texture.GetSpecialSource(sourceId.ForTextureLookup); image.Source = source; image.Width = source.PixelWidth; image.Height = source.PixelHeight; base.Create(image, sourceId.Cache, true); if (sourceId.DynamicColor) { // Note: This tint effect does not apply additive blending // (because theoretically the non-additive version should be faster). // Additive-ness is already applied at the image source. // (Ditto for Opaque blending) canvas.Effect = tintEffect = TintEffect.Create(TintEffectMode.Normal); } if (sourceId.DynamicRectangle) { image.Clip = clipGeometry = new SWM.RectangleGeometry(); } }
WriteableBitmap CreateSourceFor(ImageSourceId id) { BitmapSource original = ImageSource; // Note: need to recreate temporaryImage each time, because Silverlight // has some very strange ideas about when to update the image dimensions Image temporaryImage = new Image(); TintEffect temporaryTintEffect = null; if (id.WantsPreTint) { temporaryTintEffect = TintEffect.Create(id.TintEffectMode); temporaryImage.Effect = temporaryTintEffect; temporaryTintEffect.Color = id.ColorForPreTint; } temporaryImage.Width = original.PixelWidth; temporaryImage.Height = original.PixelHeight; temporaryImage.Source = original; int width, height; SWM.TranslateTransform transform; if (id.UseOriginalDimentions) { width = original.PixelWidth; height = original.PixelHeight; transform = null; } else { width = id.SourceWidth; height = id.SourceHeight; transform = new SWM.TranslateTransform(); transform.X = -id.SourceX; transform.Y = -id.SourceY; } WriteableBitmap output = new WriteableBitmap(width, height); output.Render(temporaryImage, transform); output.Invalidate(); if (temporaryTintEffect != null) { temporaryImage.Effect = null; temporaryTintEffect.Release(); } return(output); }