×

Discussion Board

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

    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:
    Code:
    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()
            {
                InitializeComponent();
    
                //#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();
                        bmp.SetSource(ms);
                        /*Set breakpoint at the above line, to check the BitmapImage's PixelWidth&PixelHeight,
                         * and total size of the stream's buffer
                         */
                        imageBox.Source = bmp;
                        ms.Dispose();
                    });
                }, request);
            }
        }
    }
    HTML Code:
    <phone:PhoneApplicationPage 
        x:Class="TestImageDownloading.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        shell:SystemTray.IsVisible="True">
    
        <Grid x:Name="LayoutRoot" >
            <Image x:Name="imageBox" Stretch="None" />
        </Grid>
    
    </phone:PhoneApplicationPage>
    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
    Location
    Lempäälä/Finland
    Posts
    29,176

    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
    Location
    Kochin
    Posts
    10

    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 - Nokia 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, 15: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
  •  
×