0

I am working on Windows Phone 8 app.

I have a path to image - /Data/Images/image1.png. I am able to display this image on screen, but i want to change the width and height of the image before its rendered.

This is how i am displaying the image in webbrowser control

webbrowser.Append("<img src=""+path+ width=\"250\" height=\"250\" style=\"vertical-align:middle\" alt=\"\"></img>"/>"

Here i am setting width and height as 250x250 but i want to change that height and width as some images are not looking good.

Goofy
  • 6,098
  • 17
  • 90
  • 156
  • Could you use the `Image.FromFile` function (http://msdn.microsoft.com/en-us/library/stf701f5.aspx), then do something like this: `Image i = Image.FromFile("/Data/Images/image1.png"); webbrowser.Append("\"\""/>");` ... ? – txtechhelp May 05 '14 at 09:48
  • @txtechhelp Its gives me error that `System.Windows.Controls.Image Image.FromFile` could not be found – Goofy May 05 '14 at 10:01
  • @txtechhelp see this `there is no system.drawing in WP8`. http://stackoverflow.com/questions/10385642/convert-image-to-byte-array-on-windows-phone-7-no-system-drawing-dll-any-other-w – Goofy May 05 '14 at 10:06
  • What version of the framework are you using? – txtechhelp May 05 '14 at 10:07
  • @txtechhelp I am new to WP8, so how to check that? – Goofy May 05 '14 at 10:08
  • Apparently you're stuck with importing the .NET `System.Drawing` dll if you wish to use that namespace in WP; for your question however @OlivierPayen provides a nice solution. – txtechhelp May 05 '14 at 10:17
  • @txtechhelp any idea how i can disable only horizontall scroll for Webbrowser – Goofy May 05 '14 at 11:08

1 Answers1

5

If you want the get the size of an image, you need to load it in a BitmapImage:

int width = 0;
int height = 0;
using (var stream = Application.GetResourceStream(new Uri("Assets/test.jpg", UriKind.Relative)).Stream)
{
    var bmpi = new BitmapImage();
    bmpi.SetSource(stream);
    bmpi.CreateOptions = BitmapCreateOptions.None;
    width = bmpi.PixelWidth;
    height = bmpi.PixelHeight;
    bmpi = null; // Avoids memory leaks
}
Olivier Payen
  • 15,198
  • 7
  • 41
  • 70
  • one more question How can we disable `only horizontall scroll to webrowser control ?` so that it fits to the width and height of device – Goofy May 05 '14 at 10:34
  • can you please help me with this http://stackoverflow.com/questions/23566872/webbrowser-control-with-transparent-background – Goofy May 09 '14 at 14:36