I sent this using the 'Ask a Question' link but then found the forums and
figured it would be a better mechanism (plus it seems to allow including the
log and code).

I have been trying to do what I would think is a fairly simple task for
quite a while. I have an ImageGallery that displays a grid with a bunch of
Thumbnails. When I click a thumbnail I start a new ImageViewer activity to
display the actual image. The images are not that large (< 1MB encoded). The
ImageViewer activity crashes randomly, sometimes the first image, sometimes
I get several. It always crashes when loading the image. Seems to occur in
the GetResponseStream or DecodeStream/ByteArray. I have tried serveral
variations based on other queries I've found online. Nothing seems to make
much difference. 

The Android Log for the most recent crash was:

I/ActivityManager( 1315): Starting activity: Intent {
cmp=eti.imdss.imdssmobile/imdssmobile.ImageViewer (has extras) }
D/IMDSSMobile( 2643): 2011-10-01T12:55:52: IMDSSMobile: ImageViewer:
Generate Web Request, URL =
http://webapps.goughnour.com/SAGEDocuments/5d11db61-c52e-45bb-bc2b-191265b075e0.jpg
D/IMDSSMobile( 2643): 2011-10-01T12:55:53: IMDSSMobile: ImageViewer:
GetResponseStream
W/ActivityManager( 1315): Launch timeout has expired, giving up wake lock!
W/ActivityManager( 1315): Activity idle timeout for HistoryRecord{456ebd70
eti.imdss.imdssmobile/imdssmobile.ImageViewer}

But I don't always get the Launch timeout.

The code for the ImageViewer OnCreate method(which is pretty much everything
in the ImageViewer class) is:

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Should not need to do this here since I set it up in the
manifest
            // but that does not seem to work
            //RequestWindowFeature(WindowFeatures.NoTitle);

            SetContentView(Resource.Layout.ImageViewer);

            String url = this.Intent.GetStringExtra("url");
            if (url != null)
            {
                try
                {
                    ETILog.GetETILog().LogDebug(1, "ImageViewer: Generate
Web Request, URL = {0}", url);
                    HttpWebRequest request = HttpWebRequest.Create(url) as
HttpWebRequest;
                    using (HttpWebResponse response = request.GetResponse()
as HttpWebResponse)
                    {
                        ETILog.GetETILog().LogDebug(1, "ImageViewer:
GetResponseStream");
                        using (System.IO.Stream s =
response.GetResponseStream())
                        {
                            System.IO.MemoryStream ms = new
System.IO.MemoryStream();
                            s.CopyTo(ms);

                            BitmapFactory.Options options = new
BitmapFactory.Options { InJustDecodeBounds = true };
                            BitmapFactory.DecodeByteArray(ms.ToArray(), 0,
(int)ms.Length);

                            int sampleSize = 1;
                            while (((options.OutWidth * options.OutHeight) /
sampleSize) > 1000000)
                                sampleSize <<= 1;

                            ETILog.GetETILog().LogDebug(1, "ImageViewer:
DecodeByteArray, samples size = {0}", sampleSize);
                            options = new BitmapFactory.Options {
InSampleSize = sampleSize };
                            Bitmap bm =
BitmapFactory.DecodeByteArray(ms.ToArray(), 0, (int)ms.Length, options);
                            //Bitmap bm = BitmapFactory.DecodeStream(s);

                            ETILog.GetETILog().LogDebug(1, "ImageViewer:
SetImageBitmap");
                            ImageView iv =
FindViewById<ImageView>(Resource.Id.image_viewer);
                            iv.SetImageBitmap(bm);
                        }
                    }
                }
                catch (OutOfMemoryException ex)
                {
                    ETILog.GetETILog().LogWarning("Error displaying image",
ex);
                }
                catch (Exception ex)
                {
                    ETILog.GetETILog().LogWarning("Error displaying image",
ex);
                }
            }
        }


--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/Problems-Display-Images-tp4859655p4859655.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to