/******************************************************************************
 * ImageUtil.cs 
 * 
 * <Copyright and License> 
 * 
 * This file is part of GODS, a package for annotating medical images. 
 * 
 * Copyright (C) 2004 
 * Xuedong Chen 
 * Heri Mariwa 
 * Kimmy (Hsiang-ling) Lin 
 * Rui Yu 
 * 
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 
 * of the License, or (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 *  
 * For further questions about this file, please send email to 
 * gods@cs.umb.edu or visit us at http://gods.sourceforge.net.  
 ******************************************************************************/

using System;
using System.Drawing;

namespace GODS
{
	/// <summary>
	/// Summary description for ImageUtil.
	/// </summary>
	public class ImageUtil
	{

		public static Bitmap getBitmapFromFile(String fileName)
		{
			Bitmap bm;
			
			///The idea have tempary bitmap is trying to dispose the bitmap image
			///that read from the file, which will cause the header of the image file
			///unlocked thus you can store to that file again.
			///Reference: 
			///http://www.bobpowell.net/gdiplus_faq.htm
			///
			//bm = new Bitmap(fileName);


			Bitmap i = new Bitmap(fileName);
			//create temporary 
			bm =new Bitmap(i.Width,i.Height);
			//get graphics 
			Graphics g=Graphics.FromImage(bm);

			//copy original 
			///****Chen: originally I use g.DrawImage(i,0,0)
			///but it doesn't work correctly the image is distorted with and height
			///didn't show as original. After I specify the i.With and i.Height,
			///it becomes normal.
			///
			g.DrawImage(i,0,0,i.Width,i.Height);
			//close original 
			i.Dispose();
			g.Dispose();
				
			return bm;
		}

		private ImageUtil()
		{
			//
			// TODO: Add constructor logic here
			//
		}
	}
}
