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自编程序的更多相关文章

  1. 十万个为什么:现在还没发现“虚函数virtual”和多态性的优点,估计是因为我还没有编程序吧。

    十万个为什么:现在还没发现“虚函数virtual”和多态性的优点,估计是因为我还没有编程序吧.

  2. 两个乒乓球队进行比赛,各出三人。 甲队为a,b,c三人,乙队为x,y,z三人。 已抽签决定比赛名单。 有人向队员打听比赛的名单。 a说他不和x比,c说他不和x,z比, 请编程序找出三队赛手的名单。

    题目:两个乒乓球队进行比赛,各出三人. 甲队为a,b,c三人,乙队为x,y,z三人. 已抽签决定比赛名单. 有人向队员打听比赛的名单. a说他不和x比,c说他不和x,z比, 请编程序找出三队赛手的名单 ...

  3. 代码实现:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。 已抽签决定比赛名单。有人向队员打听比赛的名单。 a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单

    /*两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人. 已抽签决定比赛名单.有人向队员打听比赛的名单. a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单.*/ ...

  4. python基础练习题(题目 两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单)

    day14 --------------------------------------------------------------- 实例022:比赛对手 题目 两个乒乓球队进行比赛,各出三人. ...

  5. C#多线程编程序--聊聊线程

    这篇文章主要给您讲解几个基本问题,什么是线程?为什么要用线程?线程万能?这几个问题.我这篇博客是在该系列另外几篇博客之后写的,之所以不往下继续写,而是回到最初的问题,是因为我感觉到我没有很好的讲解开头 ...

  6. 利用opencv源代码和vs编程序训练分类器haartraining.cpp

    如需转载请注明本博网址:http://blog.csdn.net/ding977921830/article/details/47733363. 一  训练框架 训练人脸检測分类器须要三个步骤: (1 ...

  7. 两个乒乓球队进行比赛,各出三人。甲队为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= ...

  8. JAVA高级编程序——JDBC(连接mysql数据库)——(一)

    java要想连接数据库,就要用JDBC(java database connection),用这个jar包 (mysql-connector-java-xxx-xx-bin.jar) sun公司为我们 ...

  9. 【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[ ...

随机推荐

  1. Environment 常用方法

    * 方法:getDataDirectory()解释:返回 File ,获取 Android 数据目录.* 方法:getDownloadCacheDirectory()解释:返回 File ,获取 An ...

  2. nyoj 10 skiing 搜索+动归

    整整两天了,都打不开网页,是不是我提交的次数太多了? nyoj 10: #include<stdio.h> #include<string.h> ][],b[][]; int ...

  3. bug--java访问hdfs (Server IPC version 9 cannot communicate with client version 4 错误)

    1. 今天想做一个hdfs的java工具类,但是在连接hdfs的时候,报如下错误: Exception in thread "main" org.apache.hadoop.ipc ...

  4. 【C语言入门教程】1.3 C语言“32个”关键字

    关键字是已被C语言标准作为命令.数据类型或者固定函数名的字母组合.关键字不能被用做变量名或函数名.下面列举了C语言的32个关键字,它们遵循C语言的语法使用,形成了C程序设计语言.  序号  关键字 说 ...

  5. Android4.4 往短信收件箱中插入自定义短信(伪造短信)

    这段时间稍微有点空闲,把前一段学习Android做过的一些小项目整理整理.虽然没有什么工程量很大的项目,但是对于一个新手,解决这些问题还是花了一段时间.感觉还是非常有记录的意义呢~~~么么哒*—* 今 ...

  6. ios 客户端定位的3种方法

    1.客户端通过IP地址定位 http://int.dpool.sina.com.cn/iplookup/iplookup.php 输出:城市 1 -1 -1 中国 广东 深圳 2.客户端获取经纬度,调 ...

  7. ubuntu下修改apache2.4的rewrite

    sudo a2enmod rewrite 修改/etc/apache2/apache2.conf中 AllowOverride None 为 AllowOverride ALL 重启 service ...

  8. Javascript添加事件的addEventListener()及attachEvent()区别分析,事件委托

    Mozilla中: addEventListener的使用方式: target.addEventListener(type, listener, useCapture); target: 文档节点.d ...

  9. php写入txt换行符

    1.问题 写入txt文件想换行,老是直接输出了\r\n. 2.解决 要用双引号对\r\n进行解释,否则php会直接当字符输出. 3.例子 要求:往test.txt文本每一行后面加abc $a=file ...

  10. DOM的相关优化

    为什么要进行DOM优化? DOM对象本身也是一个js对象,所以严格来说,并不是操作这个对象慢,而是说操作了这个对象后,会触发一些浏览器行为,比如布局(layout)和绘制(paint). 首先先说一些 ...