Ejemplo n.º 1
0
    def onView(self):
        filepath = self.photoTxt.GetValue()
        img = Image(filepath, BITMAP_TYPE_ANY)
        # scale the image, preserving the aspect ratio
        W = img.GetWidth()
        H = img.GetHeight()
        if W > H:
            NewW = self.PhotoMaxSize
            NewH = self.PhotoMaxSize * H / W
        else:
            NewH = self.PhotoMaxSize
            NewW = self.PhotoMaxSize * W / H
        img = img.Scale(NewW,NewH)

        self.imageCtrl.SetBitmap(BitmapFromImage(img))
        self.panel.Refresh()
Ejemplo n.º 2
0
    def __init__(self):
        #self.log = log
        wx.Frame.__init__(self,
                          None,
                          -1,
                          'Demo for Image Caption',
                          size=(800, 600))
        panel = wx.Panel(self, -1)

        image_url_st = wx.StaticText(panel,
                                     -1,
                                     'Enter an image URL',
                                     pos=(70, 30))
        image_up_st = wx.StaticText(panel,
                                    -1,
                                    'Upload an image',
                                    pos=(270, 30))  # Text for image url
        image_url_C = wx.TextCtrl(panel,
                                  -1,
                                  'image url',
                                  pos=(60, 55),
                                  size=(135, 20))
        image_url_C.Bind(wx.EVT_TEXT, self.evtText)

        image_up_B = wx.Button(panel, -1, "Choose Image",
                               pos=(270, 55))  # buttion for image upload
        self.Bind(wx.EVT_BUTTON, self.onButtonCF, image_up_B)

        gen1 = wx.Button(panel, -1, "Download",
                         pos=(80, 90))  # buttion for url image text generate
        gen1.Bind(wx.EVT_BUTTON,
                  self.showImage)  # bind the button to image show
        gen1.Bind(wx.EVT_BUTTON,
                  self.OnButtonGT_url)  # bind the button to image choose
        #self.Bind(wx.EVT_BUTTON, self.OnButtonGT_url, gen1)

        gen2 = wx.Button(panel, -1, "Upload",
                         pos=(280, 90))  # button for up image text generate
        gen2.Bind(wx.EVT_BUTTON,
                  self.showImage)  # bind the button to image show
        gen2.Bind(wx.EVT_BUTTON,
                  self.OnButtonGT_cf)  # bind the button to image choose
        #self.Bind(wx.EVT_BUTTON, self.OnButtonGT_cf, gen2)

        image_url_exam = wx.StaticText(
            panel,
            -1,
            'Example Images: click to generate text',
            pos=(100, 140))

        examImage1 = wx.Image(os.getcwd() + '\example1.bmp',
                              wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        examIma_but1 = wx.BitmapButton(panel,
                                       -1,
                                       examImage1,
                                       pos=(20, 180),
                                       size=(170, 170))
        examIma_but1.Bind(wx.EVT_BUTTON,
                          self.showImage)  # bind the button to image show
        examIma_but1.Bind(wx.EVT_BUTTON,
                          self.OnButtonC1)  # bind the button to image choose 1
        #self.Bind(wx.EVT_BUTTON, self.OnButtonC1, examIma_but1)

        examImage2 = wx.Image(os.getcwd() + '\example2.bmp',
                              wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        examIma_but2 = wx.BitmapButton(panel,
                                       -1,
                                       examImage2,
                                       pos=(220, 180),
                                       size=(170, 170))
        examIma_but2.Bind(wx.EVT_BUTTON,
                          self.showImage)  # bind the button to image show
        examIma_but2.Bind(wx.EVT_BUTTON,
                          self.OnButtonC2)  # bind the button to image choose 1
        #self.Bind(wx.EVT_BUTTON, self.OnButtonC2, examIma_but2)

        examImage3 = wx.Image(os.getcwd() + '\example3.bmp',
                              wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        examIma_but3 = wx.BitmapButton(panel,
                                       -1,
                                       examImage3,
                                       pos=(20, 370),
                                       size=(170, 170))
        examIma_but3.Bind(wx.EVT_BUTTON,
                          self.showImage)  # bind the button to image show
        examIma_but3.Bind(wx.EVT_BUTTON,
                          self.OnButtonC3)  # bind the button to image choose 1
        #self.Bind(wx.EVT_BUTTON, self.OnButtonC3, examIma_but3)

        examImage4 = wx.Image(os.getcwd() + '\example4.bmp',
                              wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        examIma_but4 = wx.BitmapButton(panel,
                                       -1,
                                       examImage4,
                                       pos=(220, 370),
                                       size=(170, 170))
        examIma_but4.Bind(wx.EVT_BUTTON,
                          self.showImage)  # bind the button to image show
        examIma_but4.Bind(wx.EVT_BUTTON,
                          self.OnButtonC4)  # bind the button to image choose 1
        #self.Bind(wx.EVT_BUTTON, self.OnButtonC4, examIma_but4)

        image_show = wx.StaticText(panel, -1, 'Chossed Image: ', pos=(520, 30))

        generate = wx.Button(panel, -1, "Generate Text",
                             pos=(550,
                                  280))  # buttion for url image text generate
        self.Bind(wx.EVT_BUTTON, self.OnButtonGT, generate)

        self.image_path = 'init.jpg'
        #self.image_path = u'C:\\Users\\young\\Desktop\\Demo-gui\\examples.jpg'
        Image = wx.wx.Image(self.image_path, wx.BITMAP_TYPE_ANY)
        Image = Image.Scale(200, 200, wx.IMAGE_QUALITY_HIGH)
        Image = Image.ConvertToBitmap()
        self.Image = wx.StaticBitmap(panel, bitmap=Image, pos=(500, 65))