C/S love自编程序
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace LOVE
{
public partial class Form1 : Form
{
private int screenWidth = 0;
private int screenHeight = 0;
private int imgWidth = 255;
private int imgHeight = 240;
private Random random = new Random();
private Dictionary<int, Bitmap> imgs = new Dictionary<int, Bitmap>();
public Form1()
{
InitializeComponent();
this.TransparencyKey = this.BackColor;
screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
this.WindowState = FormWindowState.Maximized;
imgs.Add(1, global::LOVE.Properties.Resources.heart01);
imgs.Add(2, global::LOVE.Properties.Resources.heart02);
imgs.Add(3, global::LOVE.Properties.Resources.heart03);
imgs.Add(4, global::LOVE.Properties.Resources.heart04);
imgs.Add(5, global::LOVE.Properties.Resources.heart05);
imgs.Add(6, global::LOVE.Properties.Resources.heart06);
imgs.Add(7, global::LOVE.Properties.Resources.heart07);
imgs.Add(8, global::LOVE.Properties.Resources.heart08);
imgs.Add(9, global::LOVE.Properties.Resources.heart09);
}
private void Form1_Load(object sender, EventArgs e)
{
Timer _timer = new Timer();
_timer.Tick += _timer_Tick;
_timer.Interval = 500;
_timer.Start();
}
void _timer_Tick(object sender, EventArgs e)
{
Bitmap bitmap = imgs[random.Next(1, 9)];
GraphicsPath g = subGraphicsPath(bitmap);
PictureBox pcb = new PictureBox();
pcb.BackColor = System.Drawing.Color.Transparent;
//pcb.Image =
pcb.Image = bitmap;
int x = random.Next(imgWidth, screenWidth) - imgWidth;
int y = random.Next(imgHeight, screenHeight) - imgHeight;
pcb.Size = new Size(imgWidth, imgHeight);
pcb.Location = new Point(x, y);
pcb.Region = new Region(g);
this.Controls.Add(pcb);
}
/// <summary>
/// 根据图片计算GraphicsPath路径
/// </summary>
/// <param name="img">gif或者png图片</param>
/// <returns>图片不透明区域路径</returns>
public unsafe static GraphicsPath subGraphicsPath(Image img)
{
if (img == null) return null;
// 建立GraphicsPath, 给我们的位图路径计算使用
GraphicsPath g = new GraphicsPath(FillMode.Alternate);
Bitmap bitmap = new Bitmap(img);
int width = bitmap.Width;
int height = bitmap.Height;
BitmapData bmData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
byte* p = (byte*)bmData.Scan0;
int offset = bmData.Stride - width * 3;
int p0, p1, p2; // 记录左上角0,0座标的颜色值
p0 = p[0];
p1 = p[1];
p2 = p[2];
int start = -1;
// 行座标 ( Y col )
for (int Y = 0; Y < height; Y++)
{
// 列座标 ( X row )
for (int X = 0; X < width; X++)
{
if (start == -1 && (p[0] != p0 || p[1] != p1 || p[2] != p2)) //如果 之前的点没有不透明 且 不透明
{
start = X; //记录这个点
}
else if (start > -1 && (p[0] == p0 && p[1] == p1 && p[2] == p2)) //如果 之前的点是不透明 且 透明
{
g.AddRectangle(new Rectangle(start, Y, X - start, 1)); //添加之前的矩形到
start = -1;
}
if (X == width - 1 && start > -1) //如果 之前的点是不透明 且 是最后一个点
{
g.AddRectangle(new Rectangle(start, Y, X - start + 1, 1)); //添加之前的矩形到
start = -1;
}
//if (p[0] != p0 || p[1] != p1 || p[2] != p2)
// g.AddRectangle(new Rectangle(X, Y, 1, 1));
p += 3; //下一个内存地址
}
p += offset;
}
bitmap.UnlockBits(bmData);
bitmap.Dispose();
// 返回计算出来的不透明图片路径
return g;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
this.Close();
this.Dispose();
}
}
}
}
C/S love自编程序的更多相关文章
- 十万个为什么:现在还没发现“虚函数virtual”和多态性的优点,估计是因为我还没有编程序吧。
十万个为什么:现在还没发现“虚函数virtual”和多态性的优点,估计是因为我还没有编程序吧.
- 两个乒乓球队进行比赛,各出三人。 甲队为a,b,c三人,乙队为x,y,z三人。 已抽签决定比赛名单。 有人向队员打听比赛的名单。 a说他不和x比,c说他不和x,z比, 请编程序找出三队赛手的名单。
题目:两个乒乓球队进行比赛,各出三人. 甲队为a,b,c三人,乙队为x,y,z三人. 已抽签决定比赛名单. 有人向队员打听比赛的名单. a说他不和x比,c说他不和x,z比, 请编程序找出三队赛手的名单 ...
- 代码实现:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。 已抽签决定比赛名单。有人向队员打听比赛的名单。 a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单
/*两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人. 已抽签决定比赛名单.有人向队员打听比赛的名单. a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单.*/ ...
- python基础练习题(题目 两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单)
day14 --------------------------------------------------------------- 实例022:比赛对手 题目 两个乒乓球队进行比赛,各出三人. ...
- C#多线程编程序--聊聊线程
这篇文章主要给您讲解几个基本问题,什么是线程?为什么要用线程?线程万能?这几个问题.我这篇博客是在该系列另外几篇博客之后写的,之所以不往下继续写,而是回到最初的问题,是因为我感觉到我没有很好的讲解开头 ...
- 利用opencv源代码和vs编程序训练分类器haartraining.cpp
如需转载请注明本博网址:http://blog.csdn.net/ding977921830/article/details/47733363. 一 训练框架 训练人脸检測分类器须要三个步骤: (1 ...
- 两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
package C; public class Bisai { public static void main(String[] args) { String a="xyz",b= ...
- JAVA高级编程序——JDBC(连接mysql数据库)——(一)
java要想连接数据库,就要用JDBC(java database connection),用这个jar包 (mysql-connector-java-xxx-xx-bin.jar) sun公司为我们 ...
- 【Python3练习题 017】 两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比。请编程序找出三队赛手的名单。
import itertools for i in itertools.permutations('xyz'): if i[0] != 'x' and i[2] != 'x' and i[ ...
随机推荐
- C++模板学习
一.定义函数模板 template<class T> 函数定义 举个例子比较两个数大小: template<class T> int Compare(T a,T b) { ; ...
- Windows下MySQL 5.6安装及配置详细图解
一.安装前的准备 1.下载安装程序包,可到MySQL官方网站http://www.mysql.com/下载,如图1-1: 图1-1 下载后的安装文件如图1-2所示: 图1-2 二.安装 1.双击下载的 ...
- data_quick 进度
20131118 加入xml对L8卫星波段控制: 纠正波段顺序 QVProc20131125.7z: 完成L8的增强 以后的程序会添加ZY3号解析模块 QVProc20131126.7z: 新增 粗 ...
- 解决ScrollView里如果有动态更新的ChildView时会自动滚动到底部的方法
在这个ChildView的xml属性里加上 android:focusable="true" android:focusableInTouchMode="true&quo ...
- [HDU3709]Balanced Number
[HDU3709]Balanced Number 试题描述 A balanced number is a non-negative integer that can be balanced if a ...
- OpenCV成长之路(7):图像滤波
滤波实际上是信号处理里的一个概念,而图像本身也可以看成是一个二维的信号.其中像素点灰度值的高低代表信号的强弱. 高频:图像中灰度变化剧烈的点. 低频:图像中平坦的,灰度变化不大的点. 根据图像的高频与 ...
- git 教程(8)--删除文件
在Git中,删除也是一个修改操作,我们实战一下,先添加一个新文件test.txt到Git并且提交:
- 怎样将runlmbench 获取的数值传给上层app
前面那个随笔 , 已经成功将runlmbench 移植到了Android , 并成功的运行. 今天就写一下将runlmbench 获取的那些性能值传给上层 App 进行人机交互. 一开始 , 我是想直 ...
- Hashtable和HashMap类的区别
Hashtable和HashMap类有三个重要的不同之处.第一个不同主要是历史原因.Hashtable是基于陈旧的Dictionary类的,HashMap是Java 1.2引进的Map接口的一个实现. ...
- (七)理解angular中的module和injector,即依赖注入
(七)理解angular中的module和injector,即依赖注入 时间:2014-10-10 01:16:54 阅读:63060 评论:1 收藏:0 [点 ...