⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitmapview.cs

📁 CSharpDevelop:这是一个包含源代码的C#、VB.NET的编辑器。
💻 CS
字号:
// BitmapView.cs
// Copyright (C) 2000 Mike Krueger
// 
// 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.

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

using SharpDevelop.Gui;

namespace ResEdit {

	/// <summary>
    /// This class displays a bitmap in a window, the window and the bitmap can be resized.
    /// </summary>
	class BitmapView : Form
	{
		Bitmap bitmap;
		Font   font = new Font("Tahoma", 8);
		
		public BitmapView(MainWindow main, string text, Bitmap bitmap)
		{
			this.Text   = text;
			this.bitmap = bitmap;
			
			ClientSize   = new Size(bitmap.Size.Width + 100, bitmap.Size.Height + 60);
			StartPosition = FormStartPosition.CenterScreen;
			TopMost       = true;
			Owner        = main;
		}
		protected override void OnResize(EventArgs e)
		{
			Refresh();
		}
		
		protected override void OnPaint(PaintEventArgs e)
		{
			Graphics g = e.Graphics;
			
			// calculate zoom factor 
			int BitmapWitdh  = Width - 50;
			int BitmapHeight = Height - 50;
			
			float factor1 = (float)BitmapWitdh / bitmap.Width;
			float factor2 = (float)BitmapHeight / bitmap.Height;
			float factor  = Math.Min(factor1, factor2); // always take the minimum zoom factor -> zoomed bitmap fits in the window
			BitmapWitdh  = (int)factor * bitmap.Width;
			BitmapHeight = (int)factor * bitmap.Height;
			
			g.InterpolationMode = InterpolationMode.NearestNeighbor; // Interpolation doesn't look nice for icons, so I turn it off.
			
			// draw white window background
			g.FillRectangle(new SolidBrush(Color.White), e.ClipRectangle);
			
			// calculate bitmap position
			Point p = new Point((ClientSize.Width  - BitmapWitdh) / 2, 20);
			
			// draw "transparent" color (transparent pixels are DarkCyan)
			g.FillRectangle(new SolidBrush(Color.DarkCyan), p.X, p.Y, BitmapWitdh, BitmapHeight);
			
			// draw Image
			g.DrawImage(bitmap, p.X, p.Y, BitmapWitdh, BitmapHeight);
			
			// draw Image Border
			g.DrawRectangle(new Pen(Color.Black, 1), p.X - 1, p.Y - 1, BitmapWitdh + 1, BitmapHeight + 1);
			
			// draw Size
			g.DrawString(bitmap.Size.ToString(), 
				         font, 
				         new SolidBrush(Color.Black), 0, 0);
			
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -