您的位置:首页 > 其它

读取文字点阵。

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());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: