Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="ImageDataException"></exception>
        /// <returns></returns>
        public Bitmap GetProcessedDataImage()
        {
            // attempt to create a memory stream with raw data byte array in it
            MemoryStream ms;

            try
            {
                ms = new MemoryStream(processedData);
            }
            catch (Exception inner)
            {
                string             errMsg = "IPData.GetRawDataImage : Unable to create memory stream from raw image data.";
                ImageDataException ex     = new ImageDataException(errMsg, inner);
                log.Error(errMsg, ex);
                throw ex;
            }
            // attempt to recreate the bitmap from raw data byte array
            Bitmap b;

            try
            {
                b = (Bitmap)Image.FromStream(ms);
            }
            catch (Exception inner)
            {
                string             errMsg = "IPData.GetRawDataImage : Unable to convert memory stream to image.";
                ImageDataException ex     = new ImageDataException(errMsg, inner);
                log.Error(errMsg, ex);
                throw ex;
            }
            return(b);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="b"></param>
        /// <exception cref="ImageDataException"></exception>
        public void SetProcessedDataFromImage(Bitmap b)
        {
            // create a memory stream to store image data in temporarily
            MemoryStream ms = new MemoryStream();

            try
            {
                b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            }
            catch (Exception inner)
            {
                string             errMsg = "IPData.SetProcessedDataFromImage : Unable to save data to memory stream.";
                ImageDataException ex     = new ImageDataException(errMsg, inner);
                log.Error(errMsg, ex);
                throw ex;
            }
            // convert memory stream to array with byte information
            processedData = ms.ToArray();
            ms.Dispose();
        }
Example #3
0
        /// <summary>
        /// Sets the raw data byte array from a bitmap.  This method is used to
        /// copy in the data from the bitmap and store it in a byte array.
        /// </summary>
        /// <param name="b">Bitmap to copy to raw data byte array.</param>
        /// <exception cref="ImageDataException"></exception>
        public void SetRawDataFromImage(Bitmap b)
        {
            // create a memory stream to store image data in temporarily
            MemoryStream ms = new MemoryStream();

            try
            {
                b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            }
            catch (Exception inner)
            {
                string             errMsg = "IPData.SetRawDataFromImage : Unable to save data to memory stream.";
                ImageDataException ex     = new ImageDataException(errMsg, inner);
                log.Error(errMsg, ex);
                throw ex;
            }
            // convert memory stream to array with byte information
            rawData = ms.ToArray();
            ms.Dispose();
            // store the size of image so it can be recalled later
            imageSize = new Size(b.Width, b.Height);
        }