WPF Image Box
import clr clr.AddReference("PresentationFramework") clr.AddReference("PresentationCore"); clr.AddReference('System.Data') clr.AddReference('System.Windows.Forms') import System from System import * from System.Data import * from System.Type import GetType from System.Threading.Tasks import Task from System.Windows import * from System.Windows.Controls import * from System.Windows.Controls.Primitives import * from System.Windows.Media import * from System.Windows.Media.Imaging import * from System.Windows.Media.Effects import * from System.Windows.Shapes import Rectangle from System.Windows.Shapes import Rectangle from System.Windows.Data import Binding from System.Windows.Ink import Stroke from System.Windows.Forms import ( FolderBrowserDialog, DialogResult ) from Microsoft.Win32 import ( OpenFileDialog, SaveFileDialog ) import ctrl class WpfImage(ctrl.WpfCtrl): def __init__(self,imagefile,stretch=None,scroll=True,multiple=False,**kwargs): self.ctrl = Label() self.init(**kwargs) self.image = Image() self.image.HorizontalAlignment = HorizontalAlignment.Center self.image.VerticalAlignment = VerticalAlignment.Center if imagefile: self.image.Source = BitmapImage(System.Uri(imagefile,System.UriKind.Relative)) if stretch: self.stretch(stretch) else: self.StretchUniform() '''if size: self.image.Height = float(size); self.image.Width = float(size)''' if scroll: scroll = ScrollViewer() scroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto scroll.Content = self.image self.ctrl.Content = scroll elif multiple: stack = StackPanel() stack.Orientation = Orientation.Horizontal stack.Children.Add(self.image) self.ctrl.Content = stack else: self.ctrl.Content = self.image def stretch_none(self): self.image.Stretch = Stretch.None def stretch_fill(self): self.image.Stretch = Stretch.Fill def stretch_uniform(self): self.image.Stretch = Stretch.Uniform def stretch_uniform_to_fill(self): self.image.Stretch = Stretch.UniformToFill def stretch(self,stretch): if stretch == 'none': self.stretch_none() elif stretch == 'fill': self.stretch_fill() elif stretch == 'uniform': self.stretch_uniform() elif stretch == 'uniformfill': self.stretch_uniform_to_fill() if __name__ == "__main__": import win app = win.Win("Button Demo",320,240) b = WpfImage("Lenna.png","fill") app.set_content(b.ctrl) app.run()
댓글 없음:
댓글 쓰기