0

I have created this code

Uri _blendImageUri = new Uri(@"Assets/1.png", UriKind.Relative);
var _blendImageProvider = new StreamImageSource((System.Windows.Application.GetResourceStream(_blendImageUri).Stream));

var bf = new BlendFilter(_blendImageProvider);

Filter work nice. But I want change image size for ForegroundSource property. How can I load image with my size?

David Božjak
  • 16,887
  • 18
  • 67
  • 98
Std_Net
  • 1,076
  • 3
  • 12
  • 25
  • my size I mean that my image 1.png have size 256x256 and when I addthis image into filter this image placed in all may image, but I want change size in my 1.png and set position in some place(simple example: I have open my photo and add to this photo my wife photo, so I must set position and size for 1.png) BlenderFilter have property ForegroundSource I think I can change size in this property... – Std_Net Feb 03 '14 at 18:16

1 Answers1

1

If I understood you correctly you are trying to blend ForegroundSource with only a part of the original image? That is called local blending at it is currently not supported on the BlendFilter itself.

You can however use ReframingFilter to reframe the ForegroundSource and then blend it. Your chain will look like something like this:

using (var mainImage = new StreamImageSource(...))
using (var filterEffect = new FilterEffect(mainImage))
{
    using (var secondaryImage = new StreamImageSource(...))
    using (var secondaryFilterEffect = new FilterEffect(secondaryImage))
    using (var reframing = new ReframingFilter(new Rect(0, 0, 500, 500), 0))    //reframe your image, thus "setting" the location and size of the content when blending
    {
        secondaryFilterEffect.Filters = new [] { reframing };

        using (var blendFilter = new BlendFilter(secondaryFilterEffect)
        using (var renderer = new JpegRenderer(filterEffect))
        {
            filterEffect.Filters = new [] { blendFilter };

            await renderer.RenderAsync();
        }
    }
}

As you can see, you can use the reframing filter to position the content of your ForegroundSource so that it will only blend locally. Note that when reframeing you can set the borders outside of the image location (for example new Rect(-100, -100, 500, 500)) and the areas outside of the image will appear as black transparent areas - exactly what you need in BlendFilter.

David Božjak
  • 16,887
  • 18
  • 67
  • 98