读取文字点阵。
2004-08-17 12:08
267 查看
/***********************************************************************************
*
* Copyright (C) 2004 Ming Run.
*
* This software is provided 'as-is', without any express or implied warranty. In no
* event will the authors be held liable for (any damages arising from the use of this
* software.
*
* Permission is granted to anyone to use this software for (any purpose, including
* commercial applications, and to alter it and redistribute it freely, subject to the
* following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that
* you wrote the original software. If you use this software in a product, an
* acknowledgment (see the following) in the product documentation is required.
*
* Copyright (C) 2004 Ming Run.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
***********************************************************************************/
import System;
import System.Drawing;
import System.Windows.Forms;
import NUnit.Framework;
package Runmin.Sample
{
class ImageApplication extends Form
{
private var topPanel : Panel = new Panel();
private var bottomPanel : Panel = new Panel();
private var button : Button = new Button();
private var richTextBox : RichTextBox = new RichTextBox();
private var textBox : TextBox = new TextBox();
public function ImageApplication()
{
this("Sample Application.");
}
public function ImageApplication(caption : String)
{
this.Text = caption;
this.DockPadding.All = 5;
this.WindowState = 2;
this.Controls.Add(this.topPanel);
this.Controls.Add(this.bottomPanel);
this.topPanel.Dock = 5;
this.bottomPanel.Dock = 2;
this.bottomPanel.Size = new System.Drawing.Size(0, 18);
this.button.Dock = 4;
this.button.FlatStyle = 1;
this.button.Text = "Process";
this.textBox.Dock = 4;
this.textBox.BorderStyle = 1;
this.textBox.MaxLength = 1;
this.richTextBox.Dock = 5;
this.richTextBox.WordWrap = false;
this.richTextBox.Font = new System.Drawing.Font("Courier New", 8);
this.topPanel.Controls.Add(this.richTextBox);
this.bottomPanel.Controls.Add(this.textBox);
this.bottomPanel.Controls.Add(this.button);
this.button.add_Click(this.button_Click);
}
private function button_Click(sender, e : EventArgs)
{
var dialog : FontDialog = new FontDialog();
dialog.ShowDialog();
var bitmap : Bitmap = new Bitmap(150, 150);
var graphics : Graphics = Graphics.FromImage(bitmap);
graphics.DrawString(this.textBox.Text, dialog.Font, Brushes.Black, 0, 0);
var result : System.Text.StringBuilder = new System.Text.StringBuilder();
var x : int = 0;
var y : int = 0;
for (x = 0; x < bitmap.Width; x++)
{
for (y = 0; y < bitmap.Height; y++)
{
if (bitmap.GetPixel(y, x).ToArgb() == 0) result.Append(" ");
else result.Append("*");
}
result.Append("/n");
}
this.richTextBox.Text = result.ToString();
}
}
}
Application.Run(new Runmin.Sample.ImageApplication());
*
* Copyright (C) 2004 Ming Run.
*
* This software is provided 'as-is', without any express or implied warranty. In no
* event will the authors be held liable for (any damages arising from the use of this
* software.
*
* Permission is granted to anyone to use this software for (any purpose, including
* commercial applications, and to alter it and redistribute it freely, subject to the
* following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that
* you wrote the original software. If you use this software in a product, an
* acknowledgment (see the following) in the product documentation is required.
*
* Copyright (C) 2004 Ming Run.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
***********************************************************************************/
import System;
import System.Drawing;
import System.Windows.Forms;
import NUnit.Framework;
package Runmin.Sample
{
class ImageApplication extends Form
{
private var topPanel : Panel = new Panel();
private var bottomPanel : Panel = new Panel();
private var button : Button = new Button();
private var richTextBox : RichTextBox = new RichTextBox();
private var textBox : TextBox = new TextBox();
public function ImageApplication()
{
this("Sample Application.");
}
public function ImageApplication(caption : String)
{
this.Text = caption;
this.DockPadding.All = 5;
this.WindowState = 2;
this.Controls.Add(this.topPanel);
this.Controls.Add(this.bottomPanel);
this.topPanel.Dock = 5;
this.bottomPanel.Dock = 2;
this.bottomPanel.Size = new System.Drawing.Size(0, 18);
this.button.Dock = 4;
this.button.FlatStyle = 1;
this.button.Text = "Process";
this.textBox.Dock = 4;
this.textBox.BorderStyle = 1;
this.textBox.MaxLength = 1;
this.richTextBox.Dock = 5;
this.richTextBox.WordWrap = false;
this.richTextBox.Font = new System.Drawing.Font("Courier New", 8);
this.topPanel.Controls.Add(this.richTextBox);
this.bottomPanel.Controls.Add(this.textBox);
this.bottomPanel.Controls.Add(this.button);
this.button.add_Click(this.button_Click);
}
private function button_Click(sender, e : EventArgs)
{
var dialog : FontDialog = new FontDialog();
dialog.ShowDialog();
var bitmap : Bitmap = new Bitmap(150, 150);
var graphics : Graphics = Graphics.FromImage(bitmap);
graphics.DrawString(this.textBox.Text, dialog.Font, Brushes.Black, 0, 0);
var result : System.Text.StringBuilder = new System.Text.StringBuilder();
var x : int = 0;
var y : int = 0;
for (x = 0; x < bitmap.Width; x++)
{
for (y = 0; y < bitmap.Height; y++)
{
if (bitmap.GetPixel(y, x).ToArgb() == 0) result.Append(" ");
else result.Append("*");
}
result.Append("/n");
}
this.richTextBox.Text = result.ToString();
}
}
}
Application.Run(new Runmin.Sample.ImageApplication());
相关文章推荐
- C# 网络编程专题,初看了一下,感觉不错
- Install Oracle Application Server Core on Redhat Linux 3.0
- JSP的MS SQL SERVER数据库连接
- Java 中文问题的解决 mysql, oracle, servlet, jsp
- java文件操作
- Dev-Cpp/Mingw32 环境介绍(4)
- VB.NET中的组件开发
- Refactoring C# Code Using Visual Studio 2005
- 关于ASP在DW中的配置简介(1)
- JAVA/JSP学习系列之五(JDBC-ODBC翻页例子)
- 关于ASP在DW中的配置(1)
- getParameterValues用法
- 字串日期格式转换
- 无aspx文件部署
- 这是我们交流的平台,留下点什么东东吧!
- 高效的jsp分页查询
- 请不要轻易发脾气
- 反射的使用
- 取消Windows 2000默认共享
- 反射的使用