如何在没有窗口的情况下直接将图像变亮到屏幕上? [英] How to blit a image directly to the screen without a window?

查看:102
本文介绍了如何在没有窗口的情况下直接将图像变亮到屏幕上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示来自PNG,BITMAP,JPEG文件等的图像.在没有窗口的屏幕上?我希望图像显示时最好不要在其周围有任何框架,而无需将其作为窗口注册在任务栏上.我想将这些图像快速连续地放到屏幕上.如果它与Windows XP和Windows 7兼容,我希望这样做.我愿意下载一个外部模块.如果可以的话,请告诉我.谢谢!

How do I show a image from a PNG, BITMAP, JPEG file, ect. on the screen without a window? I want the image to appear with no frame surrounding it preferably without it registering on the task bar as a window. I would like to put these images on the screen in rapid succession. I would like it if it was compatible with Windows XP and Windows 7. I am willing to download a external module. If this is possible, please tell me. Thanks!

推荐答案

这将创建一个透明背景的成形窗口,在同一文件夹中显示"image.png"

This will create a shaped window with transparent background displaying the "image.png" in same folder

import wx

# Create a .png image with something drawn on a white background
# and put the path to it here.
IMAGE_PATH = 'image.png'


class ShapedFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Shaped Window",
                style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER)
        self.hasShape = False
        self.delta = wx.Point(0,0)

        # Load the image
        image = wx.Image(IMAGE_PATH, wx.BITMAP_TYPE_PNG)
        image.SetMaskColour(255,255,255)
        image.SetMask(True)            
        self.bmp = wx.BitmapFromImage(image)

        self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight()))
        dc = wx.ClientDC(self)
        dc.DrawBitmap(self.bmp, 0,0, True)
        self.SetWindowShape()
        self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
        self.Bind(wx.EVT_MOTION, self.OnMouseMove)
        self.Bind(wx.EVT_RIGHT_UP, self.OnExit)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
    def OnEraseBackground(self,evt=None):
        pass        
    def SetWindowShape(self, evt=None):
        r = wx.RegionFromBitmap(self.bmp)
        self.hasShape = self.SetShape(r)

    def OnDoubleClick(self, evt):
        if self.hasShape:
            self.SetShape(wx.Region())
            self.hasShape = False
        else:
            self.SetWindowShape()

    def OnPaint(self, evt):
        dc = wx.PaintDC(self)
        dc.DrawBitmap(self.bmp, 0,0, True)

    def OnExit(self, evt):
        self.Close()

    def OnLeftDown(self, evt):
        self.CaptureMouse()
        pos = self.ClientToScreen(evt.GetPosition())
        origin = self.GetPosition()
        self.delta = wx.Point(pos.x - origin.x, pos.y - origin.y)

    def OnMouseMove(self, evt):
        if evt.Dragging() and evt.LeftIsDown():
            pos = self.ClientToScreen(evt.GetPosition())
            newPos = (pos.x - self.delta.x, pos.y - self.delta.y)
            self.Move(newPos)

    def OnLeftUp(self, evt):
        if self.HasCapture():
            self.ReleaseMouse()



if __name__ == '__main__':
    app = wx.PySimpleApp()
    ShapedFrame().Show()
    app.MainLoop()

这是我使用的图像

这篇关于如何在没有窗口的情况下直接将图像变亮到屏幕上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆