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. gitlab一键安装 (转)

    原文地址:http://www.2cto.com/os/201411/353292.html 0 简介bitnami和gitlab bitnami BitNami是一个开源项目,该项目产生的开源软件包 ...

  2. GridView控件隐藏列

    GridView隐藏列visible="false" 后你就无法取得这列的值了 下面是迄今为止最简洁的解决方法了. protected void GVList_RowDataBou ...

  3. ggplot2 上篇

    title: "ggplot2 上篇" author: "li_volleyball" date: "2016年4月16日" output: ...

  4. iOS开发——网络篇——UIWebview基本使用,NSInvocation(封装类),NSMethodSignature(签名),JavaScript,抛异常,消除警告

    一.UIWebView简介 1.UIWebView什么是UIWebViewUIWebView是iOS内置的浏览器控件系统自带的Safari浏览器就是通过UIWebView实现的 UIWebView不但 ...

  5. java项目导入IntelliJ IDEA

    (0)之所以有第0步,是因为第一次倒入失败,所以从删除上次倒入的数据开始- 开始删除数据. 启动Intelli J,点击右键删除上次的导入的项目 把配置拷贝到.m2文件夹下,并且删除上次下载的一些依赖 ...

  6. [POJ3277]City Horizon

    [POJ3277]City Horizon 试题描述 Farmer John has taken his cows on a trip to the city! As the sun sets, th ...

  7. Sqli-LABS通关笔录-2

    在这个关卡学习到了 1.程序的错误不是学校收费乱来的,单引号的错误和减号的错误要明白 单引号报错. 用第一关的PAYLOAD尝试了下. 来看看源码: 那么我们构造的sql也就变成了 $sql=&quo ...

  8. web图片轮播实现

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. kill新号专题

    一.在tomcat启动脚本中看到,kill  -3

  10. docker ui

    docker run -d -p 9000:9000 --privileged -v /var/run/docker.sock:/var/run/docker.sock uifd/ui-for-doc ...