×

Discussion Board

Results 1 to 5 of 5

Hybrid View

  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    3

    Question How to convert Nokia.Graphics.Imaging.Bitmap in System.Windows.Media.ImageSource

    Hello,
    I'm trying to implement the Local Blending from the Nokia Imaging SDK. The code provided in this page uses StorageFileImageSource to load the images but I've change it with StreamImageSource. Can I do it? Becouse I'm getting no errors.

    Here's my code:
    Code:
    var streamResourceInfoBackground = new StreamResourceInfo(e.ChosenPhotoList[0].ImageStream, null);
    var streamResourceInfoForeground = new StreamResourceInfo(e.ChosenPhotoList[1].ImageStream, null);
    var streamResourceInfoForegroundMask = new StreamResourceInfo(e.ChosenPhotoList[2].ImageStream, null);
    
    using (var backgroundSource = new StreamImageSource(streamResourceInfoBackground.Stream))
    using (var foregroundImageSource = new StreamImageSource(streamResourceInfoForeground.Stream))
    using (var foregroundMaskSource = new StreamImageSource(streamResourceInfoForegroundMask.Stream))
    using (var filterEffect = new FilterEffect(backgroundSource))
    using (var blendFilter = new BlendFilter(foregroundImageSource))
    using (var renderer = new BitmapRenderer(filterEffect))
    {
        blendFilter.MaskSource = foregroundMaskSource;
        blendFilter.BlendFunction = BlendFunction.Normal;
        blendFilter.TargetArea = new Windows.Foundation.Rect(0, 0.48, 0.3, 0.3);
        blendFilter.TargetAreaRotation = -3;
        blendFilter.TargetOutputOption = OutputOption.PreserveAspectRatio;
        filterEffect.Filters = new IFilter[] { blendFilter };
        var buffer = await renderer.RenderAsync();
        fullScreenImg.Source = buffer;
    }
    But the main problem is that the "buffer" is Nokia.Graphics.Imaging.Bitmap, so how can I show it in an image control?

    Thanks!

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    475

    Re: How to convert Nokia.Graphics.Imaging.Bitmap in System.Windows.Media.ImageSource

    Imaging SDK Bitmap is rather a interface to an Image buffer memory .
    For your problem, try WriteableBitmapRenderer .
    Windows 8, Windows phone 8 or Nokia Asha developer? Go to DVLUP

  3. #3
    Registered User
    Join Date
    Apr 2014
    Posts
    3

    Re: How to convert Nokia.Graphics.Imaging.Bitmap in System.Windows.Media.ImageSource

    Thanks for the reply, but WriteableBitmapRender wants an IProviderImage source, my buffer is a Bitmap. Sorry but I can't understand how to use it. Can you provide some code?

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    475

    Re: How to convert Nokia.Graphics.Imaging.Bitmap in System.Windows.Media.ImageSource

    Replace BitmapRenderer by WriteableBitmapRenderer .
    I'm not sure if it will create the WriteableBitmap or if you must to create one.

    Code:
    var streamResourceInfoBackground = new StreamResourceInfo(e.ChosenPhotoList[0].ImageStream, null);
    var streamResourceInfoForeground = new StreamResourceInfo(e.ChosenPhotoList[1].ImageStream, null);
    var streamResourceInfoForegroundMask = new StreamResourceInfo(e.ChosenPhotoList[2].ImageStream, null);
    
    using (var backgroundSource = new StreamImageSource(streamResourceInfoBackground.Stream))
    using (var foregroundImageSource = new StreamImageSource(streamResourceInfoForeground.Stream))
    using (var foregroundMaskSource = new StreamImageSource(streamResourceInfoForegroundMask.Stream))
    using (var filterEffect = new FilterEffect(backgroundSource))
    using (var blendFilter = new BlendFilter(foregroundImageSource))
    using (var renderer = new WriteableBitmapRenderer (filterEffect))
    {
        blendFilter.MaskSource = foregroundMaskSource;
        blendFilter.BlendFunction = BlendFunction.Normal;
        blendFilter.TargetArea = new Windows.Foundation.Rect(0, 0.48, 0.3, 0.3);
        blendFilter.TargetAreaRotation = -3;
        blendFilter.TargetOutputOption = OutputOption.PreserveAspectRatio;
        filterEffect.Filters = new IFilter[] { blendFilter };
        var buffer = await renderer.RenderAsync();
        fullScreenImg.Source = buffer;
    }
    Windows 8, Windows phone 8 or Nokia Asha developer? Go to DVLUP

  5. #5
    Registered User
    Join Date
    Apr 2014
    Posts
    3

    Re: How to convert Nokia.Graphics.Imaging.Bitmap in System.Windows.Media.ImageSource

    Thanks a lot, it works!

    Now I'm posting the complete working code if anyone else needs it.

    Code:
    WriteableBitmap wb = new WriteableBitmap(500, 500);
    using (var backgroundSource = new StreamImageSource(streamResourceInfoBackground.Stream))
    using (var foregroundImageSource = new StreamImageSource(streamResourceInfoForeground.Stream))
    using (var foregroundMaskSource = new StreamImageSource(streamResourceInfoForegroundMask.Stream))
    using (var filterEffect = new FilterEffect(backgroundSource))
    using (var blendFilter = new BlendFilter(foregroundImageSource))
    using (var renderer = new WriteableBitmapRenderer(filterEffect, wb))
    {
          blendFilter.MaskSource = foregroundMaskSource;
          blendFilter.BlendFunction = BlendFunction.Normal;
          blendFilter.TargetArea = new Windows.Foundation.Rect(0, 0.48, 0.3, 0.3);
          blendFilter.TargetAreaRotation = -3;
          blendFilter.TargetOutputOption = OutputOption.PreserveAspectRatio;
          filterEffect.Filters = new IFilter[] { blendFilter };
          var buffer = await renderer.RenderAsync();
          fullScreenImg.Source = wb;
    }

Similar Threads

  1. How to play media file in System media player in j2me????
    By mohammad_kaied in forum Mobile Java Media (Graphics & Sounds)
    Replies: 14
    Last Post: 2014-05-25, 14:57
  2. nokia media converter 2.0 & windows 7
    By elhossan in forum Streaming and Video
    Replies: 1
    Last Post: 2009-12-05, 07:31
  3. convert graphics to mbm format
    By mango7 in forum Symbian
    Replies: 3
    Last Post: 2008-11-18, 21:34
  4. is it possible to mix bitmap graphics with OpenGL ES?
    By miranda2112 in forum Symbian Media (Closed)
    Replies: 6
    Last Post: 2005-04-06, 04:43
  5. Replies: 0
    Last Post: 2004-01-19, 23:44

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×