Esempio n. 1
0
    def scale_bitmap(self, img: wx.Image):
        def get_new_size(_ow, _oh, _w, _h, on_w):
            if on_w:
                _nw = _ow - self.padding * 2
                _nh = _nw * _h / _w
            else:
                _nh = _oh - self.padding * 2
                _nw = _nh * _w / _h
            return _nw, _nh

        ow, oh = self.GetSize()
        w, h = img.GetSize()
        nw, nh = img.GetSize()
        if w > h:  # 横向图
            if w > ow:
                nw, nh = get_new_size(ow, oh, w, h, True)
                if nh > oh:
                    nw, nh = get_new_size(ow, oh, w, h, False)
            elif h > oh:
                nw, nh = get_new_size(ow, oh, w, h, False)
                if nw > ow:
                    nw, nh = get_new_size(ow, oh, w, h, True)
        else:  # 纵向图
            if h > oh:
                nw, nh = get_new_size(ow, oh, w, h, False)
                if nw > ow:
                    nw, nh = get_new_size(ow, oh, w, h, True)
            elif w > ow:
                nw, nh = get_new_size(ow, oh, w, h, True)
                if nh > oh:
                    nw, nh = get_new_size(ow, oh, w, h, False)

        img = img.Scale(nw, nh, wx.IMAGE_QUALITY_HIGH)
        bitmap = wx.BitmapFromImage(img)
        return bitmap
Esempio n. 2
0
def wx_to_pil(img: wx.Image):
    '''turn a WX bitmap into a PIL image one'''
    #Make a new image setting the size
    pil_img = Image.new('RGB', (img.GetWidth(), img.GetHeight()))
    pil_img.frombytes(bytes(img.GetData()))  #Copy the data into the new image

    return pil_img  #Return that new image
Esempio n. 3
0
 def convert_image(self):
     if not os.path.exists(self.image_path):
         return False
     image = Image(self.image_path, wx.BITMAP_TYPE_PNG)
     width = image.GetWidth() / 4
     height = image.GetHeight() / 4
     return image.Scale(width, height).ConvertToBitmap()
Esempio n. 4
0
def resizeImageToFit(image: wx.Image, max_width, max_height):
    r_w = max_width * 1.0 / image.GetWidth()
    r_h = max_height * 1.0 / image.GetHeight()

    r = min(r_w, r_h)
    new_width = image.GetWidth() * r
    new_height = image.GetHeight() * r

    image.Rescale(new_width, new_height)
Esempio n. 5
0
 def scale_bitmap(self, image: wx.Image):
     w = image.GetWidth()
     h = image.GetHeight()
     if w > h:
         ratio = 512 / w
     else:
         ratio = 512 / h
     image = image.Scale(int(w * ratio), int(h * ratio),
                         wx.IMAGE_QUALITY_HIGH)
     result = wx.BitmapFromImage(image)
     return result
Esempio n. 6
0
 def bitmapFromData(self, data):
     # get the data shape
     height, width, depth = data.shape
     # flatten to byte string
     flatdata = data.tostring()
     # create image of the right shape
     image = Image(width, height)
     # load image with byte string
     image.SetData(flatdata)
     # convert image to bitmap
     bitmap = image.ConvertToBitmap()
     # done
     return bitmap
Esempio n. 7
0
def rescale_image(image: wx.Image, max_width: int, max_height: int):
    """
	Rescale a wx.Image and return a wx.Bitmap.
	"""
    width, height = image.GetSize()
    ratio = width / height
    new_width = int(ratio * max_height)
    new_height = int(max_width / ratio)
    if new_width <= max_width:
        image.Rescale(new_width, max_height, wx.IMAGE_QUALITY_HIGH)
    else:
        image.Rescale(max_width, new_height, wx.IMAGE_QUALITY_HIGH)
    return wx.Bitmap(image)
Esempio n. 8
0
def gethtml(url):
    loginurl='https://www.douban.com/'    # 登录页面

    browser = webdriver.PhantomJS()s
    browser.get(loginurl)    # 请求登录页面
    browser.find_element_by_name('form_email').clear()  # 获取用户名输入框,并先清空
    browser.find_element_by_name('form_email').send_keys(u'*****@*****.**') # 输入用户名
    browser.find_element_by_name('form_password').clear()  # 获取密码框,并清空
    browser.find_element_by_name('form_password').send_keys(u'hjk12345') # 输入密码

    # 验证码手动处理,输入后,需要将图片关闭才能继续执行下一步
    captcha_link = browser.find_element_by_id('captcha_image').get_attribute('src')
    urllib.request.urlretrieve(captcha_link,'captcha.jpg')
    Image.open('captcha.jpg').show()
    captcha_code = input('Pls input captcha code:')
    browser.find_element_by_id('captcha_field').send_keys(captcha_code)

    browser.find_element_by_css_selector('input[class="bn-submit"]').click()
    browser.get(url)
    browser.implicitly_wait(10)
    return(browser)
Esempio n. 9
0
def _loadimage(path, return_bitmap = False):
    try:
        if path.isfile():
            img = Image(path, BITMAP_TYPE_ANY)
        else:
            f = None
            try:
                f = zipopen(path)
                if f is None:
                    raise IOError('Image ' + path + ' does not exist')
                img = ImageFromString(f.read())
            finally:
                if f is not None:
                    f.close()

        if not img.HasAlpha():
            img.InitAlpha()

        val = img if not return_bitmap else BitmapFromImage(img)
        val.path = path
        return val

    except Exception, err:
        raise AssertionError(err)
Esempio n. 10
0
    def load_image(self, path, area=None):
        self.Scroll(0, 0)
        self.img_path = path
        self.wx_image = Image(path, BITMAP_TYPE_ANY)
        width = self.wx_image.GetWidth()
        height = self.wx_image.GetHeight()
        if area:
            x, y, w, h = area
            bitmap = Bitmap(self.wx_image)
            bitmap_to_draw = bitmap.GetSubBitmap(Rect(x, y, w, h))

            bitmap = bitmap.ConvertToImage().ConvertToGreyscale(
                0.156, 0.308, 0.060).ConvertToBitmap()

            self.original_bitmap = self._get_bitmap(bitmap, bitmap_to_draw, x,
                                                    y, w, h, False)
        else:
            self.original_bitmap = Bitmap(self.wx_image)
        self.greyscaled_bitmap = self.original_bitmap.ConvertToImage(
        ).ConvertToGreyscale(0.209, 0.411, 0.080).ConvertToBitmap()

        self.static_bitmap.SetBitmap(self.original_bitmap)
        self.SetScrollbars(self.MIN_SCROLL, self.MIN_SCROLL,
                           width / self.MIN_SCROLL, height / self.MIN_SCROLL)
Esempio n. 11
0
def IconFromSymbolic(image:wx.Image, color:wx.Colour):
    new_image = image.Copy()

    c_r = color.Red()
    c_g = color.Green()
    c_b = color.Blue()

    for x in range(0, new_image.Width):
        for y in range(0, new_image.Height):
            r = new_image.GetRed(x,y)
            g = new_image.GetRed(x,y)
            b = new_image.GetRed(x,y)

            if r == 128 and g == 128 and b == 128:
                new_image.SetRGB(x, y, c_r, c_g, c_b)

    return new_image
Esempio n. 12
0
    def __init__(self, image: wx.Image = None, **kwargs):
        wx.Panel.__init__(self, **kwargs)
        self._f_data = None
        self._a_data = None
        self._f_fft_data = None
        self._a_fft_data = None
        self.set_default_data()

        bitmap = self.get_data_bitmap(
        ) if image is None else image.ConvertToBitmap()
        self.bmp = wx.StaticBitmap(parent=self,
                                   bitmap=bitmap,
                                   pos=(self.padding, self.padding))

        self.SetMinSize((bitmap.GetWidth() + self.padding * 2,
                         bitmap.GetHeight() + self.padding * 2))

        self.Bind(wx.EVT_MOUSEWHEEL, self.on_mousewheel_scroll, self.bmp)
Esempio n. 13
0
def getImage():
    stream = cStringIO.StringIO(getData())
    return Image(stream)
Esempio n. 14
0
import wx
from libs import Utility
import os
import sys
from libs import ADB_Command as adb
import shutil
from libs.Notebook.Panel import LogcatConfig
import logging
from wx import Image

log = logging.getLogger(__name__)
TMP = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "TMP")
if not os.path.exists(TMP):
    os.makedirs(TMP)

EMPTY_IMAGE = Image(540, 270, True)


class AndroidCatchLog(wx.Panel):
    def __init__(self, parent):
        self.name = u"Android日志"
        wx.Panel.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          size=wx.DefaultSize,
                          style=wx.TAB_TRAVERSAL)
        self.SetBackgroundColour("#EDEDED")
        self.button_default_size = (50, 30)
        MainSizer = wx.BoxSizer(wx.HORIZONTAL)
        LeftSizer = wx.BoxSizer(wx.VERTICAL)
Esempio n. 15
0
def getImage( ):
	"""Return the data from the resource as a wxImage"""
	stream = cStringIO.StringIO(data)
	return Image(stream)
Esempio n. 16
0
class ImagePanel(ScrolledWindow):
    MIN_SCROLL = 10

    def __init__(self, parent):
        ScrolledWindow.__init__(self, parent)

        self.wx_image = None
        self.original_bitmap = None
        self.greyscaled_bitmap = None
        self.img_path = None

        sizer = BoxSizer(VERTICAL)
        self.static_bitmap = StaticBitmap(self)
        sizer.Add(self.static_bitmap, 1, flag=FLAG_ALL_AND_EXPAND)

        self.SetSizer(sizer)

    def was_image_loaded(self):
        return (self.img_path and self.wx_image and self.original_bitmap
                and self.greyscaled_bitmap)

    def get_image_dimensions(self):
        return (self.original_bitmap.GetWidth(),
                self.original_bitmap.GetHeight())

    def load_image(self, path, area=None):
        self.Scroll(0, 0)
        self.img_path = path
        self.wx_image = Image(path, BITMAP_TYPE_ANY)
        width = self.wx_image.GetWidth()
        height = self.wx_image.GetHeight()
        if area:
            x, y, w, h = area
            bitmap = Bitmap(self.wx_image)
            bitmap_to_draw = bitmap.GetSubBitmap(Rect(x, y, w, h))

            bitmap = bitmap.ConvertToImage().ConvertToGreyscale(
                0.156, 0.308, 0.060).ConvertToBitmap()

            self.original_bitmap = self._get_bitmap(bitmap, bitmap_to_draw, x,
                                                    y, w, h, False)
        else:
            self.original_bitmap = Bitmap(self.wx_image)
        self.greyscaled_bitmap = self.original_bitmap.ConvertToImage(
        ).ConvertToGreyscale(0.209, 0.411, 0.080).ConvertToBitmap()

        self.static_bitmap.SetBitmap(self.original_bitmap)
        self.SetScrollbars(self.MIN_SCROLL, self.MIN_SCROLL,
                           width / self.MIN_SCROLL, height / self.MIN_SCROLL)

    def _get_bitmap(self, bitmap, bitmap_to_draw, x, y, w, h, draw_frame=True):
        bitmap = bitmap.GetSubBitmap(
            Rect(0, 0, bitmap.GetWidth(), bitmap.GetHeight()))

        dc = MemoryDC()
        bdc = BufferedDC(dc)
        bdc.SelectObject(bitmap)
        bdc.DrawBitmap(bitmap_to_draw, x, y)

        if draw_frame:
            # Black rect to support white pages
            bdc.SetPen(BLACK_PEN)
            bdc.SetBrush(TRANSPARENT_BRUSH)
            bdc.DrawRectangle(x, y, w, h)

            # Grey rect to support black pages
            bdc.SetPen(GREY_PEN)
            bdc.SetBrush(TRANSPARENT_BRUSH)
            bdc.DrawRectangle(x + 1, y + 1, w - 2, h - 2)

        bdc.SelectObject(NullBitmap)
        return bitmap
Esempio n. 17
0
def getCrosshairImage():
    stream = io.BytesIO(getCrosshairData())
    return Image(stream)
Esempio n. 18
0
def _get_ratio(image: wx.Image):
    size = image.GetSize()
    width_height = size[0] / size[1]
    return width_height
Esempio n. 19
0
from numpy import zeros, frombuffer

# must be instanciated to use ConvertToBitmap
A = base.App()

w, h, d = 2, 4, 3

data0 = zeros((h, w, 3), 'uint8')
data0[:, :, ] = (10, 20, 30)

print(data0)
print('---')

flatdata0 = data0.tostring()

image0 = Image(w, h)

image0.SetData(flatdata0)

bitmap = image0.ConvertToBitmap()

image1 = bitmap.ConvertToImage()

flatdata1 = image1.GetData()

lineardata = frombuffer(flatdata1, 'uint8')

data1 = lineardata.reshape(h, w, 3)

print(data1)
print('---')
Esempio n. 20
0
    def image_ratio(self, image:wx.Image):
        w = image.GetWidth()
        h = image.GetHeight()

        return w/h
Esempio n. 21
0
def wx_to_wxbit(img: wx.Image):
    ''' Converts a wx image to a wx bitmap '''
    return img.ConvertToBitmap()