In other words, it is used to retrieve and store the opaque data as polymorphic thru the {@link org.zkoss.util.media.Media} interface.
To encode AWT image to an instance of {@link Image}, use {@link Images#encode}. @author tomyeh @see Images#encode
171172173174175176177178179180181
if (isPreview()) { if (getContentType() != null) { if (getContentType().startsWith("image")) { InputStream input = Medias.asStream(media); imagePreview.setVisible(true); image.setContent(new AImage(getName(), input)); input.close(); adjustImage(); } if (isContentTypeEditable()) { codemirror.setVisible(true);
430431432433434435436437438439440
throw new UiException("captcha must specify height"); try { //generate the distorted image based on the given text value byte[] bytes = getCaptchaEngine().generateCaptcha(Captcha.this); final AImage image = new AImage("captcha"+new Date().getTime(), bytes); setContent(image); } catch(java.io.IOException ex) { throw UiException.Aide.wrap(ex); } finally { _smartDrawCaptcha = false;
234235236237238239240241242243244
if (Strings.isBlank(getHeight())) throw new UiException("chart must specify height"); try { final AImage image = new AImage("chart"+new Date().getTime(), getEngine().drawChart(Chart.this)); setContent(image); } catch(java.io.IOException ex) { throw UiException.Aide.wrap(ex); } finally { _smartDrawChart = false;
51525354555657
float quality, boolean encodeAlpha) throws IOException { ImageEncoder encoder = ImageEncoders.newInstance(getFormat(name)); encoder.setQuality(quality); encoder.setEncodingAlpha(encodeAlpha); return new AImage(name, encoder.encode(image)); }
64656667686970
* extension with supported format. */ public static Image encode(String name, RenderedImage image) throws IOException { ImageEncoder encoder = ImageEncoders.newInstance(getFormat(name)); return new AImage(name, encoder.encode(image)); }
270271272273274275276277278279280281
} if (!alwaysNative && ctypelc != null) { if (ctypelc.startsWith("image/")) { try { return fi.isInMemory() ? new AImage(name, fi.get()): new AImage(name, fi.getInputStream()); //note: AImage converts stream to binary array } catch (Throwable ex) { if (log.debugable()) log.debug("Unknown file format: "+ctype); } } else if (ctypelc.startsWith("audio/")) {
201202203204205206207208209210211
PiePlot plot = (PiePlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Pie Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea);
263264265266267268269270271272273
PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Pie Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(this.div_chartArea);
325326327328329330331332333334335
RingPlot plot = (RingPlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Ring Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(this.div_chartArea);
390391392393394395396397398399400
plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Bar Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea);