001/**
002 * Copyright (c) 2011, The University of Southampton and the individual contributors.
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification,
006 * are permitted provided that the following conditions are met:
007 *
008 *   *  Redistributions of source code must retain the above copyright notice,
009 *      this list of conditions and the following disclaimer.
010 *
011 *   *  Redistributions in binary form must reproduce the above copyright notice,
012 *      this list of conditions and the following disclaimer in the documentation
013 *      and/or other materials provided with the distribution.
014 *
015 *   *  Neither the name of the University of Southampton nor the names of its
016 *      contributors may be used to endorse or promote products derived from this
017 *      software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030/**
031 * 
032 */
033package org.openimaj.examples.image.drawing;
034
035import java.awt.Font;
036import java.io.IOException;
037import java.net.URL;
038
039import org.openimaj.image.DisplayUtilities;
040import org.openimaj.image.FImage;
041import org.openimaj.image.ImageUtilities;
042import org.openimaj.image.MBFImage;
043import org.openimaj.image.typography.general.GeneralFont;
044
045/**
046 * Example showing alpha composition of text on an image.
047 * 
048 * @author David Dupplaw (dpd@ecs.soton.ac.uk)
049 * @created 20 Jul 2012
050 * @version $Author$, $Revision$, $Date$
051 */
052public class AlphaCompositionExample
053{
054        /**
055         * Main method
056         * 
057         * @param args
058         *            ignored
059         * @throws IOException
060         *             if image can't be loaded
061         */
062        public static void main(final String[] args) throws IOException
063        {
064                final URL imgurl = new URL("http://www.sableandhogg-gallery.co.uk/shop/images/autumn%20landscape,%20beacons.jpg");
065
066                // ------------------------------------------------------------------
067                // FImage test
068                // ------------------------------------------------------------------
069                final FImage fi1 = ImageUtilities.readF(imgurl);
070                final FImage fi2 = new FImage(300, 100);
071                fi2.drawText("HELLO", 0, 35, new GeneralFont("Arial", Font.BOLD), 48);
072
073                final FImage alpha = fi2.clone().multiplyInplace(0.5f);
074                fi1.overlayInplace(fi2, alpha, 200, 200);
075
076                DisplayUtilities.display(fi1, "Composite");
077
078                // ------------------------------------------------------------------
079                // MBFImage test
080                // ------------------------------------------------------------------
081                final MBFImage i1 = ImageUtilities.readMBF(imgurl);
082                final MBFImage i2 = new MBFImage(300, 100, 3);
083                i2.drawText("HELLO", 0, 35, new GeneralFont("Arial", Font.BOLD), 48);
084                i2.addBand(alpha);
085                i1.overlayInplace(i2, 200, 200);
086                DisplayUtilities.display(i1, "Multiband Composite");
087
088                final MBFImage i1b = ImageUtilities.readMBF(imgurl);
089                i1b.drawImage(i2, 200, 200);
090                DisplayUtilities.display(i1b, "Multiband Composite");
091        }
092}