0

I'm using C# and WPF in Surface programming, now I have an Image object, but failed to use as the background as a Button object...Here is some related code:

using System.Windows.Media.Imaging;
using System.Drawing;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;
using Microsoft.Surface.Presentation.Input;

Image image = Image.FromFile(someFile);
SurfaceButton button1 = new SurfaceButton();

Now how to do this? I've succeeded in displaying an image using ImageBrush, but this time I just want to use the Image image itself.

Elderry
  • 1,902
  • 5
  • 31
  • 45

1 Answers1

0
var imgBrush = new ImageBrush();
imgBrush.ImageSource =
        new BitmapImage(new Uri(someFile, UriKind.Absolute));
surfaceButton.Background = imgBrush;

in case if you need an image as a source you need a converter. Take a look here Convert bitmap to imagesource

Community
  • 1
  • 1
Artiom
  • 7,694
  • 3
  • 38
  • 45
  • Er...Is there a way to use my Image object to do this job? Because I hope to control my loading process. – Elderry Jul 14 '12 at 12:16
  • I haven't understood why do you need an Image, if you have a file as source (in the given example). That would be double work, am I right? Is your source a file path? or just Image? Updated my 1st answer – Artiom Jul 16 '12 at 05:25
  • My source is a file path, and I want to separate loading and display processes; I choosed the easier way yesterday, and gived up to use the Image object, at least it's an acceptable method. Thanks for your help, later I'll check your code for more information; – Elderry Jul 16 '12 at 06:25