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. nyoj 44 子串和 简单动态规划

    子串和 时间限制:5000 ms  |  内存限制:65535 KB 难度:3   描述 给定一整型数列{a1,a2...,an},找出连续非空子串{ax,ax+1,...,ay},使得该子序列的和最 ...

  2. php 调用系统命令

    system 与 exec 两者区别与联系:都会返回最后一行,命令执行成功的return返回值, 区别:system直接将输出内容echo出来,而exec将每一行输出内容保存到数组$output里. ...

  3. PHP Socket实现websocket(四)Select函数

    int select(int maxfdp,fd_set *readfds,fd_set *writefds,fd_set *errorfds,struct timeval *timeout); /* ...

  4. POJ3461——Oulipo

    1.题目大意:单字符串匹配问题 2.分析:经典KMP问题 存个模板QAQ #include <cstdio> #include <cstdlib> #include <c ...

  5. UOJ52——【UR #4】元旦激光炮

    1.题目大意:就是给你三个数组啦,然后让你找到其中的第K大,但是,不可以直接访问数组,必须通过一种函数,最后的分数 是看调用几次这个函数,100次以内10分,2000以内6分.... 2.分析:最开始 ...

  6. HDNOIP普及+提高整合

    好久没有更新博客了...这几天一直在切 HDNOIP... 正式时跪惨了...所以考完后回来奋力切出了所有题. [COJ3351]HDNOIP201601回文质数 试题描述 回文数是具有对称性的自然数 ...

  7. BZOJ 1468: Tree

    Description 真·树,问距离不大于 \(k\) 的点对个数. Sol 点分治. 同上. Code /********************************************* ...

  8. Python自动化之select解析

    select原理 网络通信被Unix系统抽象为文件的读写,通常是一个设备,由设备驱动程序提供,驱动可以知道自身的数据是否可用.支持阻塞操作的设备驱动通常会实现一组自身的等待队列,如读/写等待队列用于支 ...

  9. 微博转发关系采集,可拓展关键字采集,评论采集(Java版)

    微博模拟登录获取cookis,配置采集深度,采集一条微博转发关系页面,同时解析页面,生成一条微博的传播图,数据集可做微博影响力分析和传播分析 gitthub:https://github.com/ch ...

  10. linux 命令free -m 命令结果分析

    free -m 命令详解 free -m 分析系统内存使用情况: