Update Image Demo

Update image demo images and show most all methods.
This commit is contained in:
Metallicow
2016-10-04 13:09:36 -05:00
parent 1fe2585742
commit 8d33e811f9
7 changed files with 316 additions and 46 deletions

View File

@@ -1,45 +1,315 @@
#!/usr/bin/env python
import wx
import os
from collections import OrderedDict
import wx
import wx.lib.scrolledpanel as scrolled
from Main import opj
# IMG_QUALITY = wx.IMAGE_QUALITY_NORMAL
IMG_QUALITY = wx.IMAGE_QUALITY_HIGH
supportedBitmapTypes = OrderedDict([
(wx.BITMAP_TYPE_ANI , 'BITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).'),
(wx.BITMAP_TYPE_BMP , 'BITMAP_TYPE_BMP: Load a Windows bitmap file.'),
(wx.BITMAP_TYPE_CUR , 'BITMAP_TYPE_CUR: Load a Windows cursor file (CUR).'),
(wx.BITMAP_TYPE_GIF , 'BITMAP_TYPE_GIF: Load a GIF bitmap file.'),
(wx.BITMAP_TYPE_ICO , 'BITMAP_TYPE_ICO: Load a Windows icon file (ICO).'),
(wx.BITMAP_TYPE_JPEG , 'BITMAP_TYPE_JPEG: Load a JPEG bitmap file.'),
(wx.BITMAP_TYPE_PCX , 'BITMAP_TYPE_PCX: Load a PCX bitmap file.'),
(wx.BITMAP_TYPE_PNG , 'BITMAP_TYPE_PNG: Load a PNG bitmap file.'),
(wx.BITMAP_TYPE_PNM , 'BITMAP_TYPE_PNM: Load a PNM bitmap file.'),
(wx.BITMAP_TYPE_TGA , 'BITMAP_TYPE_TGA: Load a TGA bitmap file.'),
(wx.BITMAP_TYPE_TIFF , 'BITMAP_TYPE_TIFF: Load a TIFF bitmap file.'),
(wx.BITMAP_TYPE_XPM , 'BITMAP_TYPE_XPM: Load a XPM bitmap file.'),
(wx.BITMAP_TYPE_ANY , 'BITMAP_TYPE_ANY: Will try to autodetect the format.'),
])
#----------------------------------------------------------------------
class ImagePanel(scrolled.ScrolledPanel):
def __init__(self, parent, id=wx.ID_ANY):
scrolled.ScrolledPanel.__init__(self, parent, id)
# self.log = log
# self.SetDoubleBuffered(True)
self.imgPath = 'bitmaps/image.png'
self.imgType = wx.BITMAP_TYPE_ANY
bmp = wx.Image(opj('bitmaps/image.bmp'), wx.BITMAP_TYPE_BMP)
gif = wx.Image(opj('bitmaps/image.gif'), wx.BITMAP_TYPE_GIF)
png = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG)
jpg = wx.Image(opj('bitmaps/image.jpg'), wx.BITMAP_TYPE_JPEG)
ico = wx.Image(opj('bitmaps/image.ico'), wx.BITMAP_TYPE_ICO)
tif = wx.Image(opj('bitmaps/image.tif'), wx.BITMAP_TYPE_TIF)
vsizer0 = wx.BoxSizer(wx.VERTICAL)
vsizer1 = wx.BoxSizer(wx.VERTICAL)
self.vsizer2 = wx.BoxSizer(wx.VERTICAL)
hsizer0 = wx.BoxSizer(wx.HORIZONTAL)
self.colorbutton = wx.ColourPickerCtrl(self, wx.ID_ANY,
style=wx.CLRP_USE_TEXTCTRL)
self.colorbutton.Bind(wx.EVT_COLOURPICKER_CHANGED, self.ChangePanelColor)
vsizer0.Add(self.colorbutton, 0, wx.ALL, 10)
self.SetBackgroundColour('#FFBB66')
self.colorbutton.SetColour('#FFBB66')
self.colorbutton.SetToolTip('Change Panel Color')
self.filebutton = wx.FilePickerCtrl(self, wx.ID_ANY,
path=os.path.abspath(opj(self.imgPath)),
message='',
wildcard=wx.Image.GetImageExtWildcard(),
style=wx.FLP_OPEN
| wx.FLP_FILE_MUST_EXIST
| wx.FLP_USE_TEXTCTRL
| wx.FLP_CHANGE_DIR
# | wx.FLP_SMALL
)
self.filebutton.SetToolTip('Browse for a image to preview modifications')
self.filebutton.Bind(wx.EVT_FILEPICKER_CHANGED, self.ChangeModdedImages)
vsizer0.Add(self.filebutton, 0, wx.ALL, 10)
defFont = wx.Font(14, wx.FONTFAMILY_DEFAULT,
wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_BOLD, True)
StatText0 = wx.StaticText(self, wx.ID_ANY,
' Unmodified image ', style=wx.BORDER)
StatText0.SetFont(defFont)
StatText0.SetBackgroundColour(wx.WHITE)
StatText0.SetForegroundColour(wx.BLACK)
vsizer0.Add(StatText0, 0, wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER, 10)
StatText1 = wx.StaticText(self, wx.ID_ANY,
' wx.Image() Bitmap Types ', style=wx.BORDER)
tt = ''
for key, value in list(supportedBitmapTypes.items()):
tt += ' wx.' + value + '\n'
StatText1.SetToolTip('Supported Bitmap Types:\n' + tt)
StatText1.SetFont(defFont)
StatText1.SetBackgroundColour(wx.WHITE)
StatText1.SetForegroundColour(wx.BLACK)
vsizer1.Add(StatText1, 0, wx.ALL | wx.ALIGN_CENTER, 10)
dict = OrderedDict([
(bmp, 'bmp\n*.bmp;*rle;*dib'),
(gif, 'gif\n*.gif'),
(png, 'png\n*.png'),
(jpg, 'jpg\n*.jpg;*.jpeg;*.jpe'),
(ico, 'ico\n*.ico'),
(tif, 'tif\n*.tif;*.tiff'),
])
for bmpType, tooltip in list(dict.items()):
statBmp = wx.StaticBitmap(self, wx.ID_ANY, bmpType.ConvertToBitmap())
type = bmpType.GetType()
if type in supportedBitmapTypes:
typeStr = 'wx.' + supportedBitmapTypes[type][:supportedBitmapTypes[type].find(':')]
statBmp.SetToolTip('This is a ' + tooltip + '\n' +
'HasAlpha = ' + str(bmpType.HasAlpha()) + '\n' +
'HasMask = ' + str(bmpType.HasMask()) + '\n' +
'Image Width = ' + str(bmpType.GetWidth()) + '\n' +
'Image Height = ' + str(bmpType.GetHeight()) + '\n' +
'GetMaskRed = ' + str(bmpType.GetMaskRed()) + '\n' +
'GetMaskGreen = ' + str(bmpType.GetMaskGreen()) + '\n' +
'GetMaskBlue = ' + str(bmpType.GetMaskBlue()) + '\n' +
'GetType = ' + typeStr + '\n' +
'\n'
)
vsizer1.Add(statBmp, 0, wx.ALL, 10)
StatText2 = wx.StaticText(self, wx.ID_ANY,
' wx.Image() Modifications ', style=wx.BORDER)
StatText2.SetFont(defFont)
StatText2.SetBackgroundColour(wx.WHITE)
StatText2.SetForegroundColour(wx.BLACK)
self.vsizer2.Add(StatText2, 0, wx.ALL | wx.ALIGN_CENTER, 10)
def getImg():
# Start with a fresh copy of the image to mod.
path = opj(self.imgPath)
type = self.imgType
return wx.Image(path, type)
self.allModdedStatBmps = []
self.img = getImg()
self.imgWidth = getImg().GetWidth()
self.imgHeight = getImg().GetHeight()
self.imgCenterPt = wx.Point(self.imgWidth//2, self.imgHeight//2)
imgBmp = wx.StaticBitmap(self, wx.ID_ANY, self.img.ConvertToBitmap())
vsizer0.Add(imgBmp, 1, wx.EXPAND | wx.ALIGN_CENTER, 10)
self.allModdedStatBmps.append(imgBmp)
self.greyscale = getImg().ConvertToGreyscale()
self.disabled = getImg().ConvertToDisabled()
self.mono = getImg().ConvertToMono(r=255,g=255,b=255)
self.maskIMG = getImg()
self.maskIMG.SetMaskColour(red=255,green=255,blue=255)
self.mask = self.maskIMG
self.blur = getImg().Blur(blurRadius=3)
self.blurH = getImg().BlurHorizontal(blurRadius=3)
self.blurV = getImg().BlurVertical(blurRadius=3)
self.mirrorH = getImg().Mirror(horizontally=True)
self.mirrorV = getImg().Mirror(horizontally=False)
self.mirrorBoth = getImg().Mirror(True).Mirror(False)
self.adjustChan = getImg().AdjustChannels(factor_red=2.0,
factor_green=1.0,
factor_blue=1.0,
factor_alpha=1.0)
self.rotate = getImg().Rotate(angle=45.0,
rotationCentre=self.imgCenterPt,
interpolating=True,
offsetAfterRotation=None)
self.rotate90 = getImg().Rotate90(clockwise=True)
self.rotate180 = getImg().Rotate180()
self.replaceIMG = getImg()
self.replaceIMG.Replace(r1=0, g1=0, b1=0, r2=0, g2=255, b2=0)
self.replace = self.replaceIMG
self.scale = getImg().Scale(width=128, height=32, quality=IMG_QUALITY)
self.rescale = getImg().Rescale(width=128, height=32, quality=IMG_QUALITY)
self.resize = getImg().Resize(size=(256 + 16, 64 + 8),
pos=(0+8, 0+4), red=0, green=0, blue=255)
self.pasteIMG = getImg()
self.pasteIMG.Paste(image=getImg(), x=16, y=16)
self.paste = self.pasteIMG
self.rotatehueIMG = getImg()
self.rotatehueIMG.RotateHue(0.5)
self.rotatehue = self.rotatehueIMG
dict = OrderedDict([
(self.greyscale , 'Image().ConvertToGreyscale()'),
(self.disabled , 'Image().ConvertToDisabled()'),
(self.mono , 'Image().ConvertToMono(r=255,g=255,b=255)'),
(self.mask , 'Image.SetMaskColour(red=255,green=255,blue=255)'),
(self.blur , 'Image().Blur(blurRadius=3)'),
(self.blurH , 'Image().BlurHorizontal(blurRadius=3)'),
(self.blurV , 'Image().BlurVertical(blurRadius=3)'),
(self.mirrorH , 'Image().Mirror(horizontally=True)'),
(self.mirrorV , 'Image().Mirror(horizontally=False)'),
(self.mirrorBoth , 'Image().Mirror(horizontally=True).Mirror(horizontally=False)'),
(self.adjustChan , 'Image().AdjustChannels(factor_red=2.0, factor_green=1.0, factor_blue=1.0, factor_alpha=1.0)'),
(self.rotate , 'Image().Rotate(angle=45.0, rotationCentre=imgCenterPt, interpolating=True, offsetAfterRotation=None)'),
(self.rotate90 , 'Image().Rotate90(clockwise=True)'),
(self.rotate180 , 'Image().Rotate180()'),
(self.replace , 'Image.Replace(r1=0, g1=0, b1=0, r2=0, g2=255, b2=0)'),
(self.scale , 'Image().Scale(width=128, height=32, quality=wx.IMAGE_QUALITY_NORMAL)'),
(self.rescale , 'Image().Rescale(width=128, height=32, quality=wx.IMAGE_QUALITY_NORMAL)'),
(self.resize , 'Image().Resize(size=(256 + 16, 64 + 8), pos=(0+8, 0+4), red=0, green=0, blue=255)'),
(self.paste , 'Image.Paste(image=getImg(), x=16, y=16)'),
(self.rotatehue , 'Image.RotateHue(0.5)'),
])
for imgModification, tooltip in list(dict.items()):
statBmp = wx.StaticBitmap(self, wx.ID_ANY,
imgModification.ConvertToBitmap())
statBmp.SetToolTip('This is a ' + tooltip)
self.allModdedStatBmps.append(statBmp)
self.vsizer2.Add(statBmp, 0, wx.ALL, 10)
hsizer0.Add(vsizer1)
hsizer0.Add(self.vsizer2)
vsizer0.Add(hsizer0)
self.SetSizer(vsizer0)
self.SetupScrolling()
def ChangePanelColor(self, event):
color = event.GetColour()
self.SetBackgroundColour(color)
self.Refresh()
def ChangeModdedImages(self, event):
changedpath = event.GetPath()
print(changedpath)
def getImg():
# Start with a fresh copy of the image to mod.
path = opj(changedpath)
type = self.imgType
return wx.Image(path, type)
self.img = getImg()
self.imgWidth = getImg().GetWidth()
self.imgHeight = getImg().GetHeight()
self.imgCenterPt = wx.Point(self.imgWidth//2, self.imgHeight//2)
self.greyscale = getImg().ConvertToGreyscale()
self.disabled = getImg().ConvertToDisabled()
self.mono = getImg().ConvertToMono(r=255,g=255,b=255)
self.maskIMG = getImg()
self.maskIMG.SetMaskColour(red=255,green=255,blue=255)
self.mask = self.maskIMG
self.blur = getImg().Blur(blurRadius=3)
self.blurH = getImg().BlurHorizontal(blurRadius=3)
self.blurV = getImg().BlurVertical(blurRadius=3)
self.mirrorH = getImg().Mirror(horizontally=True)
self.mirrorV = getImg().Mirror(horizontally=False)
self.mirrorBoth = getImg().Mirror(True).Mirror(False)
self.adjustChan = getImg().AdjustChannels(factor_red=2.0,
factor_green=1.0,
factor_blue=1.0,
factor_alpha=1.0)
self.rotate = getImg().Rotate(angle=45.0,
rotationCentre=self.imgCenterPt,
interpolating=True,
offsetAfterRotation=None)
self.rotate90 = getImg().Rotate90(clockwise=True)
self.rotate180 = getImg().Rotate180()
self.replaceIMG = getImg()
self.replaceIMG.Replace(r1=0, g1=0, b1=0, r2=0, g2=255, b2=0)
self.replace = self.replaceIMG
self.scale = getImg().Scale(width=128, height=32, quality=IMG_QUALITY)
self.rescale = getImg().Rescale(width=128, height=32, quality=IMG_QUALITY)
self.resize = getImg().Resize(size=(256 + 16, 64 + 8),
pos=(0+8, 0+4), red=0, green=0, blue=255)
self.pasteIMG = getImg()
self.pasteIMG.Paste(image=getImg(), x=16, y=16)
self.paste = self.pasteIMG
self.rotatehueIMG = getImg()
self.rotatehueIMG.RotateHue(0.5)
self.rotatehue = self.rotatehueIMG
list = [self.img ,
self.greyscale ,
self.disabled ,
self.mono ,
self.mask ,
self.blur ,
self.blurH ,
self.blurV ,
self.mirrorH ,
self.mirrorV ,
self.mirrorBoth ,
self.adjustChan ,
self.rotate ,
self.rotate90 ,
self.rotate180 ,
self.replace ,
self.scale ,
self.rescale ,
self.resize ,
self.paste ,
self.rotatehue
]
for imgModification in range(len(list)):
self.allModdedStatBmps[imgModification].SetBitmap(list[imgModification].ConvertToBitmap())
self.vsizer2.RecalcSizes()
self.PostSizeEvent()
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
vsizer = wx.BoxSizer(wx.VERTICAL)
vsizer.Add(ImagePanel(self), 1, wx.EXPAND | wx.ALL, 0)
self.SetAutoLayout(1)
self.SetSizer(vsizer)
def runTest(frame, nb, log):
bmp = wx.Image(opj('bitmaps/image.bmp'), wx.BITMAP_TYPE_BMP).ConvertToBitmap()
gif = wx.Image(opj('bitmaps/image.gif'), wx.BITMAP_TYPE_GIF).ConvertToBitmap()
png = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
jpg = wx.Image(opj('bitmaps/image.jpg'), wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
panel = wx.Panel(nb, -1)
pos = 10
wx.StaticBitmap(panel, -1, bmp, (10, pos))
pos = pos + bmp.GetHeight() + 10
wx.StaticBitmap(panel, -1, gif, (10, pos))
pos = pos + gif.GetHeight() + 10
wx.StaticBitmap(panel, -1, png, (10, pos))
pos = pos + png.GetHeight() + 10
wx.StaticBitmap(panel, -1, jpg, (10, pos))
greyscale = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToGreyscale().ConvertToBitmap()
disabled = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToDisabled().ConvertToBitmap()
mono = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToMono(0,255,255).ConvertToBitmap()
pos = 10
wx.StaticBitmap(panel, -1, greyscale, (320, pos))
pos = pos + greyscale.GetHeight() + 10
wx.StaticBitmap(panel, -1, disabled, (320, pos))
pos = pos + disabled.GetHeight() + 10
wx.StaticBitmap(panel, -1, mono, (320, pos))
panel = TestPanel(nb, log)
return panel
@@ -50,18 +320,18 @@ def runTest(frame, nb, log):
overview = """\
<html>
<body>
This class encapsulates a platform-independent image. An image can be created
from data, or using <code>wxBitmap.ConvertToImage</code>. An image can be loaded from
a file in a variety of formats, and is extensible to new formats via image
format handlers. Functions are available to set and get image bits, so it can
be used for basic image manipulation.
This class encapsulates a platform-independent image. An image can be created
from data, or using <code>wxBitmap.ConvertToImage</code>. An image can be loaded
from a file in a variety of formats, and is extensible to new formats via image
format handlers. Functions are available to set and get image bits, so it can
be used for basic image manipulation.
<p>The following image handlers are available. wxBMPHandler is always installed
by default. To use other image formats, install the appropriate handler or use
<p>The following image handlers are available. wxBMPHandler is always installed
by default. To use other image formats, install the appropriate handler or use
<code>wx.InitAllImageHandlers()</code>.
<p>
<table>
<table>
<tr><td width=25%>wxBMPHandler</td> <td>For loading and saving, always installed.</td></tr>
<tr><td>wxPNGHandler</td> <td>For loading and saving.</td> </tr>
<tr><td>wxJPEGHandler</td> <td>For loading and saving.</td> </tr>
@@ -70,17 +340,17 @@ by default. To use other image formats, install the appropriate handler or use
<tr><td>wxPNMHandler</td> <td>For loading and saving.</td> </tr>
<tr><td>wxTIFFHandler</td> <td>For loading and saving.</td> </tr>
<tr><td>wxIFFHandler</td> <td>For loading only.</td> </tr>
<tr><td>wxXPMHandler</td> <td>For loading and saving.</td> </tr>
<tr><td>wxXPMHandler</td> <td>For loading and saving.</td> </tr>
<tr><td>wxICOHandler</td> <td>For loading and saving.</td> </tr>
<tr><td>wxCURHandler</td> <td>For loading and saving.</td> </tr>
<tr><td>wxANIHandler</td> <td>For loading only.</td> </tr>
</table>
<p>When saving in PCX format, wxPCXHandler will count the number of different
colours in the image; if there are 256 or less colours, it will save as 8 bit,
<p>When saving in PCX format, wxPCXHandler will count the number of different
colours in the image; if there are 256 or less colours, it will save as 8 bit,
else it will save as 24 bit.
<p>Loading PNMs only works for ASCII or raw RGB images. When saving in PNM format,
<p>Loading PNMs only works for ASCII or raw RGB images. When saving in PNM format,
wxPNMHandler will always save as raw RGB.
</body>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 14 KiB

BIN
demo/bitmaps/image.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 19 KiB

BIN
demo/bitmaps/image.tif Normal file

Binary file not shown.