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. Ubuntu 14 编译安装 PHP 5.4.45 + Nginx 1.4.7 + MySQL 5.6.26 笔记

    Ubuntu 14 编译安装 PHP 5.4.45 + Nginx  1.8.0/1.4.7 + MySQL 5.6.26 笔记,主要是给自己的PC机安装,非生产环境! 一.下载必要的源码 1.1.下 ...

  2. Mac Pro 入门、遇到的问题、个性化设置 汇总

    入门资料 入门一:Mac 基本用法 入门二:Mac 使用VMware Fusion虚拟机 入门三:Mac 使用brew安装软件 问题汇总 [问题1]如何复制文本? 一只手指头按下,另外一只手指头滑动选 ...

  3. java之Date

    1.java时间处理 package com.bmkit.util.date; import java.text.DateFormat; import java.text.ParseException ...

  4. Lvs原理

    官方文档: http://www.linuxvirtualserver.org/zh/lvs1.html http://www.linuxvirtualserver.org/zh/lvs2.html ...

  5. 再谈select, iocp, epoll,kqueue及各种I/O复用机制

    原文:http://blog.csdn.net/shallwake/article/details/5265287 首先,介绍几种常见的I/O模型及其区别,如下: blocking I/O nonbl ...

  6. JVM内存监控工具 JavaMelody

    这是一个需要web部署的工具,需要在容器中部署,然后将要监控的程序添加到该程序中即可. JavaMelody是java应用的监控工具,安装部署步骤如下: 1. 首先先下载javamelody.jar ...

  7. ubuntu安装python一些安装包

    sudo apt-get install python-pip sudo pip install distribute sudo pip install nose sudo pip install v ...

  8. NFS和mount常用参数详解

    NFS权限参数配置 ro 只读访问 rw 读写访问 sync 所有数据在请求时写入共享 async NFS在写入数据前可以相应请求 secure NFS通过1024以下的安全TCP/IP端口发送 in ...

  9. VB中 ByRef与ByVal区别

    函数调用的参数传递有"值传递"和"引用传递"两种传递方式.如果采用"值传递",在函数内部改变了参数的值,主调程序的对应变量的值不会改变:如果 ...

  10. IDEA 配置 tomcat 启动内存

    -server -XX:PermSize=128M -XX:MaxPermSize=256m