rect

android 通过修改图片像素实现CircleImageView

匿名 (未验证) 提交于 2019-12-02 23:52:01
CircleImageView实现方法有很多种,各有优缺点,因此需要按照不同的场景使用。我们今天使用修改图片像素的方法实现CircleImageView,主要知识点无非是勾股定理和点到圆形的距离。 素材图片 : 效果如下: ** 1、clipPath裁剪画布 ** 该方法支持的最小版本是Android 4.3(API Level 18),方便快捷,但是不支持硬件加,此外也存在Path既有的缺点,不支持抗锯齿。 @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint (); mBitmap = BitmapFactory . decodeResource ( getResources (), R . drawable . pic ); mPath = new Path (); mPath . addCircle ( mBitmap . getWidth () / 2 , mBitmap . getHeight () / 2 , mBitmap . getWidth () / 2 , Path . Direction . CCW ); canvas . clipPath ( mPath ); canvas . drawBitmap ( mBitmap ,

pygame坦克大战前夕

匿名 (未验证) 提交于 2019-12-02 23:47:01
最近想自己写pygame版的坦克大战,今晚已经完成如下功能: 1,我方坦克,可手动移动;敌方坦克,自动转方向与移动 2,坦克颜色随机,坦克形态大小可调。 3,双方坦克速度可调。 4,刷新坦克的位置随机。 5,坦克不会出界。 6,游戏窗口大小可调。 目前存在的问题: 1,表示坦克方向的列表,还未放到类里。 2,坦克会重叠(碰撞检测)。 3,炮弹类还未写。 4,...... # !/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan import pygame import random from pygame.locals import * pygame.init() FPS = pygame.time.Clock() fps = 10 screen_x = 640 screen_y = 480 # 退出标识符 done = False fill_color = 0, 0, 0 # 黑色 surface = pygame.display.set_mode((screen_x, screen_y)) pygame.display.set_caption("Draw a tank") # 小方块边长,一辆坦克是是7*7个小方块组成的 blockage = 5 tank_u = [1, 0, 0, 3, 0, 0,

Unity 屏幕坐标到UGUI RectTransform本地坐标的转换

匿名 (未验证) 提交于 2019-12-02 23:47:01
public static bool ScreenPointToLocalPointInRectangle(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector2 localPoint); rect: 对应的 RectTransform 的引用 screenPoint: 位置,基于屏幕坐标系 cam: 相机的引用,如果Canvas的Render Mode 为 Screen Space - Camera 模式,则需要填入 Render Camera 对应的引用 localPoint: rect 本地坐标系下的坐标(原点(0,0)位置受Anchor的影响) 参考: https://docs.unity3d.com/ScriptReference/RectTransformUtility.ScreenPointToLocalPointInRectangle.html using UnityEngine; using UnityEngine.UI; using System.Collections; using UnityEngine.EventSystems; public class GlobalTest : MonoBehaviour { public Canvas canvas; Text uiText;

ios 自定义圆环加载进度

匿名 (未验证) 提交于 2019-12-02 23:43:01
2019独角兽企业重金招聘Python工程师标准>>> 效果 #import <UIKit/UIKit.h> @interface HWCircleView : UIView @property (nonatomic, assign) CGFloat progress; //进度条颜色 @property(nonatomic,strong) UIColor *progerssColor; //进度条背景颜色 @property(nonatomic,strong) UIColor *progerssBackgroundColor; //进度条的宽度 @property(nonatomic,assign) CGFloat progerWidth; //进度数据字体大小 @property(nonatomic,assign)CGFloat percentageFontSize; //进度数字颜色 @property(nonatomic,strong) UIColor *percentFontColor; @end #import "HWCircleView.h" @interface HWCircleView () @property (nonatomic, weak) UILabel *cLabel; @end @implementation HWCircleView -

使用pyzbar解析二维码图片

匿名 (未验证) 提交于 2019-12-02 23:34:01
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wyBluewind/article/details/90340456 需要依赖pyzbar库,依赖zbar库,可搜索安装。 from pyzbar . pyzbar import decode from PIL import Image import os import cv2 import numpy as np def test_image_dir ( ) : for one in os . listdir ( "./images" ) : # image=cv2.imread(filepath) image = Image . open ( "./images/" + one ) results = decode ( image ) info = "{}\t size: {} " . format ( one , len ( results ) ) for res in results : info += "{}({}), {}\t" . format ( res . data , res . type , res . rect ) # print("size: {}".format(len(a))) # print(a[0].type, a[0].data, a[0]

从完全零基础教你用Python开饭一款打飞机的游戏!是个人就能学会

匿名 (未验证) 提交于 2019-12-02 22:56:40
默认图片左上角为原点 (0,0)。 显示窗口 如果我们这样设定,当我们运行的时候,窗口会一闪而过,并不会出现我们想象的画面。因为窗口只是运行一下就会关闭,所以我们要写一个循环,使窗口一直保持出现。当然如果我们简单的写一个 while True那么我们的程序就出现了死循环,卡死。 同时我们的资源文件里还有一个叫做 shoot.pack 的文件,里面记录了每个图片所在的位置。 我们通过下面的代码加载资源图片,并且获得我们需要的主角飞机。 下一步就是完善这四个方法。 简单的说就是按下方向键的时候(w,a,s,d)飞机向四周移动,但是不能移动离开屏幕。 此时我们就应该把我们的飞机形成一个类,类里面有控制飞机的方法。 这里写类比较麻烦一点 player的控制 当飞机出现了,我们就应该实现我们在循环里写的方法。我们首先要判断它还在不在屏幕内,不能让飞机飞出屏幕。可以通过 rect.top,rect.bottom,rect.left,rect.right四个方法获取飞机图片的上下左右四个边界值。 这样我们就能对飞机进行判断 让子弹飞 子弹要沿着发射方向射出去。可以在屏幕上一直移动,直到移出屏幕。 我们只要有定义一个子弹对象,让这个对象显示在屏幕上就可以。 先定义飞机子弹类,基本和定义 player 一样,获得图片,裁剪图片,设置图片初始位置,在屏幕上显示图片 下一步就是让飞机的子弹跟随飞机。

Python 使用Opencv实现前景检测

匿名 (未验证) 提交于 2019-12-02 22:51:30
欢迎加入学习交流QQ群:657341423 前景检测在平面设计来说,称之为抠图,,OpenCV的抠图是由grabCut函数实现。grabCut是一种算法,算法原理说明如下: 函数原型: grabCut ( img , mask , rect , bgdModel , fgdModel , iterCount , mode = None ) img - 输入图像 mask-掩模图像,用来确定那些区域是背景,前景,可能是前景/背景等。可以设置为:cv2.GC_BGD,cv2.GC_FGD,cv2.GC_PR_BGD,cv2.GC_PR_FGD,或者直接输入 0,1,2,3 也行。 rect - 包含前景的矩形,格式为 (x,y,w,h) bdgModel, fgdModel - 算法内部使用的数组. 你只需要创建两个大小为 (1,65),数据类型为 np.float64 的数组。 iterCount - 算法的迭代次数 mode - cv2.GC_INIT_WITH_RECT 或 cv2.GC_INIT_WITH_MASK,使用矩阵模式还是蒙板模式。 示例 import numpy as np import cv2 from matplotlib import pyplot as plt img = cv2 . imread ( 'varese.jpg' ) mask = np .

第十二章―武装飞船

匿名 (未验证) 提交于 2019-12-02 22:51:30
12-1 蓝色天空 :创建一个背景为蓝色的Pygame窗口。 1 import sys 2 import pygame 3 def run_game(): 4 #初始化游戏并创建一个屏幕对象 5 pygame.init() 6 screen=pygame.display.set_mode((1200,800)) 7 pygame.display.set_caption("Alien Invasion") 8 #设置背景颜色 9 bg_color=(0,0,255) 10 #开始游戏的主循环 11 while True: 12 #监视键盘和鼠标事件 13 for event in pygame.event.get(): 14 if event.type==pygame.QUIT: 15 sys.exit() 16 #每次循环时都会重绘屏幕 17 screen.fill(bg_color) 18 #让最近绘制的屏幕可见 19 pygame.display.flip() 20 run_game() 输出: 12-2 游戏角色 :找一幅你喜欢的游戏角色位图图像或将一幅图像转换为位图。创建一个类,将该角色绘制到屏幕中央,并将该图像的背景色设置为屏幕背景色,或将 屏幕背景色设置为该图像的背景色。 alien_invasion1.py 1 import sys 2 import pygame 3

python dlib 人脸检测

匿名 (未验证) 提交于 2019-12-02 22:51:30
1. anaconda 安装dlib库: 安装命令: https://anaconda.org/conda-forge/dlib 打开Anaconda Prompt:输入 conda install -c conda-forge dlib=19.9 等待安装完成即可; 2. 测试示例 方法1:基于Hog-SVM人脸检测器 方法2:基于深度卷积神经网络实现的人脸检测 # -*- coding: utf-8 -*- """ Created on Mon Jun 17 16:51:46 2019 @author: zfjuan """ import cv2 import dlib img = cv2.imread('.\\image\\keliamoniz1.jpg'); ''' #方法1: # 使用 Dlib 的正面人脸检测器 frontal_face_detector detector = dlib.get_frontal_face_detector() # 使用 detector 检测器来检测图像中的人脸 # use detector of Dlib to detector faces faces = detector(img, 1) print("人脸数 / Faces in all: ", len(faces)) # Traversal every face for i, d

c#继承类实例

匿名 (未验证) 提交于 2019-12-02 22:06:11
在现有类(基类、父类)上建立新类(派生类、子类)的处理过程称为继承。派生类能自动获得基类的除了构造函数和析构函数以外的所有成员,可以在派生类中添加新的属性和方法扩展其功能。 继承的特性: 可传递性:C从B派生,B从A派生,那么C不仅继承B也继承A。 单一性:只能从一个基类中继承,不能同时继承多个基类继承中的访问修饰符base和this关键字基类的构造函数和析构函数不能被继承的。但可以使用关键字base来继承基类的构造函数。 C#中的base关键字代表基类,使用base关键字可以调用基类的构造函数、属性和方法。 namespace InheritanceApplication { class Shape { public void setWidth(int w) { width = w; } public void setHeight(int h) { height = h; } protected int width; protected int height; } // 派生类 class Rectangle: Shape { public int getArea() { return (width * height); } } class RectangleTester { static void Main(string[] args) { Rectangle Rect =