Advertisement
Kimossab

marre

Mar 30th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1. import clr
  2. import os
  3. import tempfile
  4. import threading
  5. clr.AddReference('System')
  6. clr.AddReference('System.Windows.Forms')
  7. clr.AddReference('System.Drawing')
  8.  
  9. from System import IO
  10. from System.IO import Path, File
  11. from System.Windows.Forms import Application, DockStyle, Form, PictureBox, PictureBoxSizeMode, Timer, FormBorderStyle, MessageBox, ControlStyles
  12. from System.Drawing import Image, Bitmap, Rectangle, Size, Color
  13. from time import sleep
  14.  
  15. pathToFile = 'C:\Users\Kimossab\Desktop\marretesting.png'
  16. col = 4
  17. lin = 2
  18.  
  19. def GetRectangle(img):
  20.     h = img.Height/lin
  21.     w = img.Width/col
  22.     return [w,h]
  23.  
  24. def CropImage(img, rect):
  25.     bmpCrop = img.Clone(rect,img.PixelFormat)
  26.     return bmpCrop
  27.  
  28.  
  29.  
  30. class MainForm(Form):
  31.  
  32.     def Draw(self):
  33.         retan = Rectangle(self.ccol*self.ret[0],self.clin*self.ret[1],self.ret[0],self.ret[1])
  34.         self.ccol+=1
  35.         if self.ccol == col:
  36.             self.ccol = 0
  37.             self.clin+=1
  38.         if self.clin == lin:
  39.             self.clin = 0;
  40.         self.pictureBox.Image = CropImage(self.image,retan)
  41.  
  42.     def __init__(self):
  43.         try:
  44.             Form.__init__(self)
  45.             self.SetStyle(ControlStyles.SupportsTransparentBackColor, 1);
  46.             self.ccol = 0
  47.             self.clin = 0
  48.             self.pictureBox = PictureBox()
  49.             self.image = Image.FromFile(pathToFile)
  50.             self.ret = GetRectangle(self.image)
  51.             retan = Rectangle(0,0,self.ret[0],self.ret[1])
  52.             self.ClientSize = Size(self.ret[0],self.ret[1])
  53.             self.FormBorderStyle = FormBorderStyle.None
  54.             self.BackColor = Color.Red
  55.             self.TransparencyKey = self.BackColor
  56.  
  57.             self.pictureBox.SizeMode = PictureBoxSizeMode.StretchImage
  58.             self.pictureBox.Dock = DockStyle.Fill
  59.  
  60.             self.timer = Timer()
  61.             self.timer.Interval = 1
  62.             self.timer.Enabled = True
  63.             self.timer.Tick += self.OnTick
  64.             self.timer.Start()
  65.  
  66.             self.Controls.Add(self.pictureBox)
  67.  
  68.             self.Show()
  69.         except Exception as inst:
  70.             MessageBox.Show(inst.message)
  71.  
  72.     def OnTick(self, sender, event):
  73.         self.Draw()
  74.         self.Refresh()
  75.  
  76.  
  77. Application.EnableVisualStyles()
  78. form = MainForm()
  79. Application.Run(form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement