Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Dec 2011

    Question Why does BitmapImage.SetSource() get a image of 1/4 of the correct resolution?

    In my app, i use HttpWebRequest to get picture data from server, then set the data into a BitmapImage, which is finally set as source of an image control. Background code and XAML are shown below:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using System.IO;
    using System.Windows.Media.Imaging;
    namespace TestImageDownloading
        public partial class MainPage : PhoneApplicationPage
            // Constructor
            public MainPage()
                //#1  A narrow and tall picture gets the problem:
                Uri uri = new Uri("http://t1.qpic.cn/mblogpic/79442e7095e63fe941fc/2000", UriKind.Absolute);
                //#2  Other pictures seems to be right:
                ///// Uri uri = new Uri("http://t1.qpic.cn/mblogpic/919f93bde512a2137bce/2000", UriKind.Absolute);
                var request = (HttpWebRequest)WebRequest.Create(uri);
                request.Method = "GET";
                request.Accept = "image/*";
                request.BeginGetResponse(asyncResult =>
                    var response = (HttpWebResponse)request.EndGetResponse(asyncResult);
                    int length = Int32.Parse(response.ContentLength.ToString());
                    var byteData = new byte[length];
                    using (var reader = new BinaryReader(response.GetResponseStream()))
                        reader.Read(byteData, 0, length);
                    MemoryStream ms = new MemoryStream(byteData);
                    Dispatcher.BeginInvoke(() =>
                        BitmapImage bmp = new BitmapImage();
                        /*Set breakpoint at the above line, to check the BitmapImage's PixelWidth&PixelHeight,
                         * and total size of the stream's buffer
                        imageBox.Source = bmp;
                }, request);
    HTML Code:
        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        <Grid x:Name="LayoutRoot" >
            <Image x:Name="imageBox" Stretch="None" />
    Something strange happens when getting pictures with long height and short width: After bmp.SetSource(ms), you can see its PixelHeight and PixelWidth are quarter of those of the correct picture(to confirm this, just open the picture's url in browser and save it as file). But length of buffer of the stream is equal to the size of the picture file. And other pictures have no suck problem !
    Why does it happen? And how to make the downloaded BitmapImage correct ?

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003

    Re: Why does BitmapImage.SetSource() get a image of 1/4 of the correct resolution?

    Could it be the issue discussed in here: http://stackoverflow.com/questions/3...in-silverlight

  3. #3
    Registered User
    Join Date
    Jan 2012

    Re: Why does BitmapImage.SetSource() get a image of 1/4 of the correct resolution?

    Instead of using bitmapimage try using writablebitmap...

Similar Threads

  1. Screen Resolution of E90 is not correct on RDA
    By sameerbkamble in forum Feedback - Developer Services & Infrastructure
    Replies: 6
    Last Post: 2011-07-26, 19:55
  2. cant get correct image on 6710 using j2me
    By abhinav.goswami in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2010-05-09, 15:34
  3. What is the Image Resolution....??
    By srinivasreddy501 in forum Mobile Java General
    Replies: 2
    Last Post: 2010-02-10, 16:50
  4. Get the resolution of an image..
    By jimdeal in forum Symbian
    Replies: 1
    Last Post: 2003-09-03, 04:05
  5. Image Resolution
    By adamfahn in forum General Messaging
    Replies: 1
    Last Post: 2003-05-09, 09:42

Posting Permissions

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