本文整理汇总了Python中javax.imageio.ImageIO类的典型用法代码示例。如果您正苦于以下问题:Python ImageIO类的具体用法?Python ImageIO怎么用?Python ImageIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImageIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_mediafiles_into_catroid_directory_structure
def save_mediafiles_into_catroid_directory_structure():
def update_md5_hash(current_md5_name, file_path_for_update):
resource_maps = list(sb2_project.project_code.resource_dicts_of_md5_name(current_md5_name))
md5_name = common.md5_hash(file_path_for_update) + os.path.splitext(file_path_for_update)[1]
for resource_map in resource_maps:
if sb2keys.COSTUME_MD5 in resource_map:
resource_map[sb2keys.COSTUME_MD5] = md5_name
elif sb2keys.SOUND_MD5 in resource_map:
resource_map[sb2keys.SOUND_MD5] = md5_name
else:
assert False, "Unknown dict: {}".resource_map
return md5_name
for md5_name, src_path in sb2_project.md5_to_resource_path_map.iteritems():
file_ext = os.path.splitext(md5_name)[1].lower()
converted_file = False
# TODO; extract method
if file_ext in {".png", ".svg", ".jpg", ".gif"}:
target_dir = images_path
# # WORKAROUNF: penLayerMD5 file
# if not resource_maps:
# continue
if file_ext == ".svg":
# converting svg to png -> new md5 and filename
src_path = svgtopng.convert(src_path)
converted_file = True
elif md5_name in sb2_project.background_md5_names:
# resize background if not matching the default resolution
imageFile = File(src_path)
pngImage = ImageIO.read(imageFile)
if pngImage.getWidth() > sb2.STAGE_WIDTH_IN_PIXELS or pngImage.getHeight() > sb2.STAGE_HEIGHT_IN_PIXELS:
resizedImage = imageresizer.resize_png(pngImage, sb2.STAGE_WIDTH_IN_PIXELS, sb2.STAGE_HEIGHT_IN_PIXELS)
# FIXME
src_path = src_path.replace(".png", "resized.png")
ImageIO.write(resizedImage, "png", File(src_path))
converted_file = True
elif file_ext in {".wav", ".mp3"}:
target_dir = sounds_path
if file_ext == ".wav":
if not wavconverter.is_android_compatible_wav(src_path):
temp_path = src_path.replace(".wav", "converted.wav")
wavconverter.convert_to_android_compatible_wav(src_path, temp_path)
src_path = temp_path
converted_file = True
else:
assert file_ext in {".json"}, md5_name
continue
assert os.path.exists(src_path), "Not existing: {}".format(src_path)
if converted_file:
md5_name = update_md5_hash(md5_name, src_path)
# if file is used multiple times: single md5, multiple filenames
for catroid_file_name in _convert_resource_name(sb2_project, md5_name):
shutil.copyfile(src_path, os.path.join(target_dir, catroid_file_name))
if converted_file:
os.remove(src_path)
示例2: __init__
def __init__(self,hostname):
self.hostname=hostname
JPanel.__init__(self,BorderLayout())
self.cbActionListener=foo2(self)
#imglist=os.listdir('./img')
#try:imglist.remove('.svn')
#except:pass
imglist=['01-CircleOfFifths.gif','Fifths.png','circle-o-fifths.jpg','Circle_Of_Fifths.gif','Keywheel.gif','circle-of-fifths.gif','ColorFifths.jpg','cof.gif']
self.cb=JComboBox(imglist,actionListener=self.cbActionListener)#
#self.cb.addItemListener(self.cbCB)
tb=JPanel()
tb.setLayout(FlowLayout(FlowLayout.CENTER))
tb.add(self.cb)
self.add(tb,'Center')
self.img=None
if hostname[0:7]=='http://':
self.img=ImageIO.read(URL(self.hostname+'/static/sightreadingtrainer/img/'+imglist[0]))
else:
self.img=ImageIO.read(File(self.hostname+'img/'+imglist[0]))
icon=ImageIcon(self.img)
self.label=JLabel(icon)
self.add(self.label,'North')
示例3: showImgWithLegend
def showImgWithLegend(width=None,height=None):
""" This function shows the image and legend from current IDV window while in GUI mode. Optional arguments are width and height in pixels, they currently default to 600 and 400"""
from java.util import Base64 ##only in java8
from javax.imageio import ImageIO
from java.io import ByteArrayOutputStream
from ucar.unidata.ui.ImageUtils import resize,toBufferedImage
import java
import java.awt.Robot as Robot
import java.awt.Rectangle as Rectangle
import java.awt.Toolkit as Toolkit
from ucar.unidata.util import Misc
VM=idv.getViewManager()
VMC=VM.getContents()
VMCC=VMC.getComponent(1) # the view and legend ; 0 is left most part of view window with controls for perspective views
siz=VMCC.getSize()
loc= VMCC.getLocationOnScreen()
gc= VMCC.getGraphicsConfiguration()
loc.x -= gc.getBounds().x
loc.y -= gc.getBounds().y
robotx=Robot(gc.getDevice())
VM.toFront()
Misc.sleep(250)
img = robotx.createScreenCapture(Rectangle(loc.x, loc.y,siz.width, siz.height))
if width != None and height != None:
img=toBufferedImage(resize(img,width,height));
bos=ByteArrayOutputStream();
ImageIO.write(img, "png", Base64.getEncoder().wrap(bos));
data = bos.toString("UTF-8");
return {"display":"image","data":data}
示例4: raster
def raster(self, filename, client):
"""Takes a filename and converts it to a raster image
reportlab can process"""
if not os.path.exists(filename):
log.error("Missing image file: %s",filename)
return missing
try:
# First try to rasterize using the suggested backend
backend = self.get_backend(filename, client)[1]
return backend.raster(filename, client)
except:
pass
# Last resort: try everything
if sys.platform[0:4] == 'java':
try:
from javax.imageio import ImageIO
from java.io import File
iis = ImageIO.createImageInputStream(File(filename))
readers = ImageIO.getImageReaders(iis)
if readers.hasNext():
reader = readers.next()
reader.setInput(iis, True)
metadata = reader.getImageMetadata(0)
# this means imageio can read it
return filename
else:
log.warning("Java's ImageIO cannot read the file [%s]", filename)
except Exception, error:
log.warning("Could not use Java's ImageIO to read the file [%s]: %s", filename, str(error))
示例5: showImgWithFullWindow
def showImgWithFullWindow(width=None,height=None):
""" This function shows the image from current IDV window while in GUI mode. optional arguments are width and height in pixels, they
currently default to 600 and 400"""
from java.util import Base64 ##only in java8
from javax.imageio import ImageIO
from java.io import ByteArrayOutputStream
from ucar.unidata.ui.ImageUtils import resize,toBufferedImage
import java
import java.awt.Robot as Robot
import java.awt.Rectangle as Rectangle
import java.awt.Toolkit as Toolkit
from ucar.unidata.util import Misc
VM=idv.getViewManager()
myframe=VM.getDisplayWindow().getComponent()
robotx = Robot(myframe.getGraphicsConfiguration().getDevice())
VM.toFront();
#robotx.delay(250)
Misc.sleep(350)
pause()
img=robotx.createScreenCapture(Rectangle( myframe.getX(),myframe.getY(),myframe.getWidth(),myframe.getHeight()))
if width != None and height != None:
img=toBufferedImage(resize(img,width,height));
bos=ByteArrayOutputStream();
ImageIO.write(img, "png", Base64.getEncoder().wrap(bos));
data = bos.toString("UTF-8");
return {"display":"image","data":data}
示例6: test_parse_svgfile_and_convert_to_png_antenna
def test_parse_svgfile_and_convert_to_png_antenna(self):
img_proc_dir = os.path.join(helpers.APP_PATH, "test", "res", "img_proc_png")
input_svg_path = os.path.join(img_proc_dir, "input_antenna.svg")
expected_image_path = os.path.join(img_proc_dir, "expected_antenna.png")
assert os.path.exists(input_svg_path)
rotation_x, rotation_y = 53, 43
output_png_path = svgtopng.convert(input_svg_path, rotation_x, rotation_y)
from javax.imageio import ImageIO
from java.io import File
bufferd_image = ImageIO.read(File(output_png_path))
width, height = bufferd_image.getWidth(), bufferd_image.getHeight()
output_image_matrix = [[bufferd_image.getRGB(i, j) for j in xrange(height)] for i in xrange(width)]
bufferd_image = ImageIO.read(File(expected_image_path))
width, height = bufferd_image.getWidth(), bufferd_image.getHeight()
expected_image_matrix = [[bufferd_image.getRGB(i, j) for j in xrange(height)] for i in xrange(width)]
for i in xrange(width):
for j in xrange(height):
exp_rgb_val = expected_image_matrix[i][j]
result_rgb_val = output_image_matrix[i][j]
assert exp_rgb_val == result_rgb_val
示例7: image_byte_array
def image_byte_array(self):
baos = ByteArrayOutputStream();
ImageIO.write( self.image(), "png", baos );
baos.flush();
image_bytes = baos.toByteArray();
baos.close()
return image_bytes
示例8: render_shape_to_graphics
def render_shape_to_graphics(self, shape):
r = shape.getShapeRenderer()
# Find the size that the shape will be rendered to at the specified scale and resolution.
shapeSizeInPixels = r.getSizeInPixels(1.0, 96.0)
# Rotating the shape may result in clipping as the image canvas is too small. Find the longest side
# and make sure that the graphics canvas is large enough to compensate for this.
maxSide = Math.max(shapeSizeInPixels.width, shapeSizeInPixels.height)
image = BufferedImage(int(maxSide * 1.25), int(maxSide * 1.25), BufferedImage.TYPE_INT_ARGB)
# Rendering to a graphics object means we can specify settings and transformations to be applied to
# the shape that is rendered. In our case we will rotate the rendered shape.
gr = image.getGraphics()
# Clear the shape with the background color of the document.
gr.setBackground(shape.getDocument().getPageColor())
gr.clearRect(0, 0, image.getWidth(), image.getHeight())
# Center the rotation using translation method below
gr.translate(image.getWidth() / 8, image.getHeight() / 2)
# Rotate the image by 45 degrees.
gr.rotate(45 * Math.PI / 180)
# Undo the translation.
gr.translate(-image.getWidth() / 8, -image.getHeight() / 2)
# Render the shape onto the graphics object.
r.renderToSize(gr, 0, 0, shapeSizeInPixels.width, shapeSizeInPixels.height)
ImageIO.write(image, "png", File(self.dataDir + "TestFile.RenderToGraphics.png"))
gr.dispose()
print "Shape rendered to Graphics successfully."
示例9: outputFiles
def outputFiles(self, filename, attachLogo=False, logoText=None):
rendered = self.getTarget().screenshot()
if attachLogo:
from java.awt.image import BufferedImage
from com.raytheon.uf.common.localization import PathManagerFactory
noaa = 'pyViz/logos/noaalogo2.png'
nws = 'pyViz/logos/nwslogo.png'
pathMgr = PathManagerFactory.getPathManager()
noaa = pathMgr.getStaticFile(noaa)
nws = pathMgr.getStaticFile(nws)
noaaImage = ImageIO.read(noaa)
nwsImage = ImageIO.read(nws)
height = rendered.getHeight() + noaaImage.getHeight()
finalBuf = BufferedImage(rendered.getWidth(), height, BufferedImage.TYPE_INT_ARGB)
graphics = finalBuf.createGraphics()
graphics.drawImage(rendered, 0, 0, None)
graphics.drawImage(noaaImage, 0, rendered.getHeight(), None)
graphics.fillRect(noaaImage.getWidth(), rendered.getHeight(), rendered.getWidth() - noaaImage.getWidth() - nwsImage.getWidth(), rendered.getHeight())
if logoText is not None:
from java.awt import Color
from com.raytheon.uf.viz.core.font import FontAdapter
graphics.setColor(Color.BLACK)
graphics.setFont(FontAdapter.getAWTFont(self.getTarget().getDefaultFont()))
fm = graphics.getFontMetrics()
textBounds = fm.getStringBounds(logoText, graphics)
graphics.drawString(logoText, int((rendered.getWidth() - textBounds.getWidth()) / 2), \
int(rendered.getHeight() + (noaaImage.getHeight() / 2) + textBounds.getHeight() / 2))
graphics.drawImage(nwsImage, finalBuf.getWidth() - nwsImage.getWidth(), rendered.getHeight(), None)
finalBuf.flush()
self.outputImage(finalBuf, filename)
else:
self.outputImage(rendered, filename)
示例10: BufferedImgToNotebook
def BufferedImgToNotebook(img):
from java.io import ByteArrayOutputStream
from java.util import Base64 ##only in java8
from javax.imageio import ImageIO
bos=ByteArrayOutputStream();
ImageIO.write(img, "png", Base64.getEncoder().wrap(bos));
data = bos.toString("UTF-8");
return {"display":"image","data":data}
示例11: jpg2bmp
def jpg2bmp(src):
# load jpg
b = bmp_name(src)
f = File(src)
image = ImageIO.read(f)
output = File(b)
ImageIO.write(image,"bmp",output)
示例12: _screenshot
def _screenshot(name):
name = name.replace("<","-").replace(">","-").replace(":","-").replace("|","-").replace("*","-").replace("\"","-").replace("/","-").replace("\\","-")
from java.awt import Toolkit,Robot,Rectangle
from javax.imageio import ImageIO
from java.io import File
screenRect = Rectangle(Toolkit.getDefaultToolkit().getScreenSize())
capture = Robot().createScreenCapture(screenRect)
ImageIO.write(capture, "png", File(_UXTST_OUTPUT_PATH_ + name+".png"))
示例13: getimage
def getimage(self) :
if not os.path.exists('tools/image.png') :
imagedata = 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ\nbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdp\nbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6\neD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEz\nNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJo\ndHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1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4FwFTo9vkgMXEIVIY/yWIvVTR+3dnI505kQgQqvs2uSJoF/nltxOdVVQaGzfNdRyucUQtGLRi1\ngAIAEGAAimxsT0J9RpkAAAAASUVORK5CYII=\n'
actual_image = base64.b64decode(imagedata)
from java.io import ByteArrayInputStream
stream = ByteArrayInputStream(actual_image)
self._image = ImageIO.read(stream);
else :
self._image = ImageIO.read(File('tools/image.png'))
示例14: __output_image
def __output_image(self, f):
out = io.FileOutputStream(f)
size = self.preferredSize
im = image.BufferedImage(size.width, size.height, image.BufferedImage.TYPE_INT_RGB)
g2d = im.getGraphics()
self.paint(g2d)
ImageIO.write(im,'png',out)
out.close()
gui_status_bar.show_message("Image saved.")
示例15: saveToPNG
def saveToPNG(p,filename):
from java.awt.image import BufferedImage
from javax.imageio import ImageIO
from java.io import File
bi = BufferedImage(p.size.width, p.size.height, BufferedImage.TYPE_INT_ARGB)
g = bi.createGraphics()
p.invalidate()
p.validate()
p.paint(g)
g.dispose();
ImageIO.write(bi,"png", File(filename));