

Using pydicom with Python Imaging Library (PIL) ¶ It creates a Tkinter PhotoImage in a Label widget or a user-supplied widget. Tkinter graphics system, which comes by default with most Python installations.
#Wxpython imageviewer how to
In the contrib-pydicom repository demonstrates how to show an image using the Thanks to Roy Keyes for pointing out how to do this. Self.imageBox.> import matplotlib.pyplot as plt > import pydicom > from pydicom.data import get_testdata_files > filename = get_testdata_files ( "CT_small.dcm" ) > ds = pydicom. If imgPos + self.height <= boxPos + and deltaY < 0:

If imgPos + self.width = boxPos and deltaY > 0: If event.GetWheelRotation() :Ĭompare = imgPos + - boxPos. If self.url and self.GetStatusBar(): #close is seen as a size event. If image.lower().endswith('jpg') or image.lower().endswith('png') or image.lower().endswith('jpeg') or image.lower().endswith('gif') or image.lower().endswith('bmp'): Tmp = wx.StaticBitmap(self.imageBox,wx.ID_ANY,bmp,(x,y)) Wximg.SetAlphaData(img.convert("RGBA").tostring()) Wximg.SetData(img.convert("RGB").tostring()) Self.SetStatusText(str(index+1) + '/' + str(self.numOfPics), 3) Self.SetStatusText(str(ogWidth) + 'x' + str(ogHeight), 1)

Img = img.resize((int(self.width),int(self.height)),mode) (wx.EVT_SIZE, lambda evt: self.rescale(evt,1)) #self.url = os.getcwd() + '\\' + sys.argv (self.imageBox,proportion=1,flag = wx.EXPAND) Self.moveCursor = wx.StockCursor(wx.CURSOR_SIZING) Self.cursor = wx.StockCursor(wx.CURSOR_ARROW) Wx.Frame._init_(self,None,title = "viewer")
#Wxpython imageviewer windows
# There are several lines that are Windows specific. # line 54, then do "viewer.py sampleImage" # To run this file from command line, comment out line 55 and uncomment # viewer is started by opening an image with it. # There is no functionality to load an image. # Left and right mouse buttons are next and previous image. # Middle button down while dragging moves image around, as do arrow

# Images under 1000x1000 are automatically on high quality. # m changes PIL mode from low quality (fast) to high quality (slow). I guess the main functions you'll want to look at are processPicture and showPicture.Įdit: and just to reiterate, I started this with the example in this tutorial. Sorry for the non-descriptive variable names and lack of comments. I'm new here, and after searching for a while I still can't find a way to upload files.
#Wxpython imageviewer code
Sample code and links to sources (of something that is not too bloated) are welcome. I'm using Python with wxPython/wxWidgets and PIL, but the question is to a large extent language- and platform- independent. Any ideas how to do it in a neat way? Or is what I feel as being ugly just the only way to go? Then one needs to figure out how to convert image coordinates to scrolling coordinates.īoth ways look awkward. Scrollbars updating (when 'hand tool' used) and operation (when used directly) code needs to be written.Ģ) An oversized control (StaticBitmap or whatever) containing the image is put inside a window with automatic scrolling. The image (or it's part) is then drawn on some window/control in an overridden onPaint() method. Two solutions that are obvious to me are:ġ) Resizing and cropping the visible part of the image is crafted on its own using functionality of some image manipulation library. There seems to be several options for achieving this goal, differing mainly in degree of putting responsibilities on the graphical interface framework as opposed to manually implementing things. The main concern is how to implement (in terms of gui components and image manipulation) such features as: zoom in-out, scroll and 'hand tool'.
