Welcome to MSDN Blogs Sign in | Join | Help

Dealing with PersonalImage

PersonalImage is a type that encapsulates the picture that shows up for a person in the health record.

My current image is this:

With the power to... Melt!

(those interested into why that is my current image should post the results of their research in the comments)

PersonalImage is what is called a Singleton type, which - as you've probably already figured out - means that there can only be one of them. But, there might be none of them, so code needs to handle this case as well.

Here's some code you might find useful.

        using (Stream imageStream = System.IO.File.OpenRead(@"C:\Documents and Settings\ericgu\My Documents\My Pictures\213.jpg"))
        {
            HealthRecordItemCollection collection = PersonInfo.SelectedRecord.GetItemsByType(PersonalImage.TypeId, HealthRecordItemSections.All);

            PersonalImage image = null;

            if (collection.Count != 0)
            {
                image = collection[0] as PersonalImage;

                using (Stream currentImageStream = image.ReadImage())
                {
                    byte[] imageBytes = new byte[currentImageStream.Length];
                    currentImageStream.Read(imageBytes, 0, (int)currentImageStream.Length);

                    using (FileStream outputImage = System.IO.File.OpenWrite(@"g:\213.jpg"))
                    {
                        outputImage.Write(imageBytes, 0, imageBytes.Length);
                    }
                }
            }


            if (image == null)
            {
                image = new PersonalImage();
                image.WriteImage(imageStream, "image/jpg");
                PersonInfo.SelectedRecord.NewItem(image);
            }
            else
            {
                image.WriteImage(imageStream, "image/jpg");
                PersonInfo.SelectedRecord.UpdateItem(image);
            }
        }

Published Thursday, March 06, 2008 1:57 PM by ericgu
Filed under:

Comments

# Daily Bits - March 7, 2008 | Alvin Ashcraft's Daily Geek Bits

Friday, March 07, 2008 4:45 PM by Wife, PhD

# re: Dealing with PersonalImage

The guy he works with is "...super strong and super naked!" and he has a crush on a woman who "...flies—like thunder!"

New Comments to this post are disabled
 
Page view tracker