How can I create a shadow text effect?

How can I add a blur effect to text on a BufferedImage. I am trying to create a shadow text effect. Here is what I have currently.
BufferedImage image = new BufferedImage(500,120,BufferedImage.TYPE_INT_RGB);
Rectangle2D Rectangle = new Rectangle2D.Double(0,0,500,120);
Graphics graphics = image.getGraphics();
Graphics2D g2d = (Graphics2D) graphics;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setPaint(Color.white);
g2d.fill(Rectangle);
g2d.draw(Rectangle);
//Shadow text
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
shadow = new TextLayout("Shadow Text", new Font("Serif", Font.BOLD, 70), g2d.getFontRenderContext());
g2d.setPaint(Color.lightGray);
shadow.draw(g2d, 13, 103);
//Main text
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
text = new TextLayout("Shadow Text", new Font("Serif", Font.BOLD, 70), g2d.getFontRenderContext());
g2d.setPaint(Color.black);
text.draw(g2d, 10, 100);
I found a blur effect but it affect the whole image not just the shadow. Here is an example.
BufferedImage image = new BufferedImage(500,120,BufferedImage.TYPE_INT_RGB);
Rectangle2D Rectangle = new Rectangle2D.Double(0,0,500,120);
Graphics graphics = image.getGraphics();
Graphics2D g2d = (Graphics2D) graphics;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setPaint(Color.white);
g2d.fill(Rectangle);
g2d.draw(Rectangle);
//Shadow text
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
shadow = new TextLayout("Shadow Text", new Font("Serif", Font.BOLD, 70), g2d.getFontRenderContext());
g2d.setPaint(Color.lightGray);
shadow.draw(g2d, 13, 103);
Blur filter
float ninth = 1.0f / 9.0f;
float[] kernel = {ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth};
biop = new ConvolveOp(new Kernel(3, 3, kernel));
op = (BufferedImageOp) biop;
image = op.filter(image,null);
//Main text
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
text = new TextLayout("Shadow Text", new Font("Serif", Font.BOLD, 70), g2d.getFontRenderContext());
g2d.setPaint(Color.black);
text.draw(g2d, 10, 100);

I thought I answered that question?!
In your code above, watch out for statement:
image = op.filter(image,null); The resulted buffered image is new, so you are updating the reference held in variable image.
Unfortunately variable g2d is still refering to a graphics object back by the original image, so:
g2d.setPaint(Color.black);
text.draw(g2d, 10, 100);renders on the first buffered image, not the second.
Here's my code again, touched up a bit.
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;
import javax.swing.*;
public class ShadowText {
    public static void main(String[] args) throws IOException {
        int w = 500;
        int h = 120;
        Font font = new Font("Lucida Bright", Font.ITALIC, 72);
        String text = "Shadow Text";
        BufferedImage image = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
        Graphics2D g = image.createGraphics();
        adjustGraphics(g);
        //start off all white:
        g.setPaint(Color.WHITE);
        g.fillRect(0, 0, w, h);
        //draw "shadow" text: to be blurred next
        TextLayout textLayout = new TextLayout(text, font, g.getFontRenderContext());
        g.setPaint(new Color(128,128,255));
        textLayout.draw(g, 15, 105);
        g.dispose();
        //blur the shadow: result is sorted in image2
        float ninth = 1.0f / 9.0f;
        float[] kernel = {ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth};
        ConvolveOp op = new ConvolveOp(new Kernel(3, 3, kernel), ConvolveOp.EDGE_NO_OP, null);
        BufferedImage image2 = op.filter(image,null);
        //write "original" text on top of shadow
        Graphics2D g2 = image2.createGraphics();
        adjustGraphics(g2);
        g2.setPaint(Color.BLACK);
        textLayout.draw(g2, 10, 100);
        //save to file
        ImageIO.write(image2, "jpeg", new File("ShadowText.jpg"));
        //show me the result
        display(image2);
    static void adjustGraphics(Graphics2D g) {
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    static void display(BufferedImage im) {
        JFrame f = new JFrame("ShadowText");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new JLabel(new ImageIcon(im)));
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
}

Similar Messages

  • How can I create drop shadows with PSE10

    How can I create drop shadows with PSE10 & PE10?

    Layer styles let you quickly apply effects to an entire layer. In the Effects panel, you can view a variety of predefined layer styles and apply a style with just a click of the mouse.
    Three different layer styles applied to text 
    The boundaries of the effect are automatically updated when you edit that layer. For example, if you apply a drop shadow style to a text layer, the shadow changes automatically when you edit the text.
    Layer styles are cumulative, which means that you can create a complex effect by applying multiple styles to a layer. You can apply one style from each style library per layer. You can also change a layer’s style settings to adjust the final result.
    When you apply a style to a layer, a style icon appears to the right of the layer’s name in the Layers panel. Layer styles are linked to the layer contents. When you move or edit the contents of the layer, the effects are modified correspondingly.
    Once you choose Layer > Layer Style > Style Settings, you can edit the settings of a layer’s style or apply other style settings or attributes available in the dialog box.
    Lighting Angle Specifies the lighting angle at which the effect is applied to the layer.
    Drop Shadow
    Specifies the distance of a drop shadow from the layer’s content. You can also set the size and opacity with the sliders.
    Outer Glow Size Specifies the size of a glow that emanates from the outside edges of the layer’s content. You can also set the opacity with the slider.
    Inner Glow Size Specifies the size of a glow that emanates from the inside edges of the layer’s content. You can also set the opacity with the slider.
    Bevel Size Specifies the size of beveling along the inside edges of the layer’s content.
    Bevel Direction Specifies the direction of the bevel, either up or down.
    Stroke Size Specifies the size of the stroke.
    Stroke Opacity Specifies the opacity of the stroke.

  • How can I create a video with effects using my ipad?

    How can I create a video with effects (sepia, B&W, Negative, oval or any other shape borders) using my ipad?  I would Like to keep a higher res and also be able to shrink it down to email or send in a MMS. Or should I just upload it to my PC and mess with it there? Some of the apps I have are very easy to use compared to the learning curve needed for video editing software.
    Thanks

    Thats the Problem . . . how many apps do I have to try until I find the one I want? I noticed a few will render the video thus losing its original size. When I went to edit it more in iMovie the video was smaller--not good. And what software do you suggest, Templeton, for the PC? I love the apps because they are easy. I dont have hours to mess around on a software to figure out if its something I want. Im looking for simplicity. Maybe Ill get more into it later. I just want to record simple video of my playing the guitar for self analysis and create a short video for family and friends.
    Apps:
    iMovie
    CinemaFXV
    VideoFix
    Cartoonatic
    Video illusion
    VidEditor
    Software:
    Windows Movie maker (wont accept .mov files)
    After Effects (Too little time, so much to learn)
    Wondershare (Very easy but little choices)
    VideoPad (Again. Few choices)

  • How can I get a match text effect in a Choice

    How can I get a match text effect in a Choice; I mean, for instance, that if a type a "p" the first choice item that begins with a "p" should be automatically selected

    Here is a pretty simple example. Keep in mind that I am coverting all comparison characters to UpperCase. If you allow LowerCase characters in you Choice items then remove the appropriate Character.toUpperCase() calls.
    Hope this helps
    Mike
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TestApplet extends Applet implements KeyListener {
         private Choice choice;
         public void init()
              setLayout(new FlowLayout());
              choice = new Choice();
              choice.add("Aaron");
              choice.add("Adam");
              choice.add("David");
              choice.add("Mike");
              choice.addKeyListener(this);
              add(choice);
         public void keyPressed(KeyEvent e)
              int current = choice.getSelectedIndex();
              int x = 0;
              char c = Character.toUpperCase(e.getKeyChar());
              while(x<choice.getItemCount()) {
                   if(c == Character.toUpperCase(choice.getItem(x).charAt(0))) {
                        current = x;
                        break;
                   x++;
              choice.select(current);
         public void keyReleased(KeyEvent e) { }
         public void keyTyped(KeyEvent e) { }
    }

  • How can I create an expandable text field in Acrobat XI?

    I am trying to create a text field that expands with the text that is entered. I have found several forums saying to use subforms, but how do I create those? Does anyone know where I can find a really good turtorial for XI?

    There are two type of PDF forms: AcroForms that can be created with Acrobat, and XFA forms (static and dynamic) that can be created with LiveCycle Designer. Since the kind you want (dynamic XFA) cannot be created with Acrobat, you'll have to use LiveCycle Designer. Said another way, AcroForms do not support fields that automatically expand based on content. If you want to ask about dynamic XFA forms, you can ask in the LiveCycle Designer forum: http://forums.adobe.com/community/livecycle/livecycle_modules_and_development_tools/livecy cle_designer_es

  • How can I create transparent animated  text with Motion and Final Cut Pro?

    Hi all,
    I am trying to replicate an effect that a previous video editor did in a project, but I can't contact them.
    They made animated text in Live Type, and saved it as a QT movie. When this text is placed over existing video in the FCP project, the text is "transparent", basically it acts like text created in FCP (You can see the background image behind the text, like through the middle of the letter "o").
    I have made some animated text in Motion, but when I save it as a QT movie, and bring it into FCP, the whole 1280x720 screen is covered by this movie, and I have to crop it so it does not cover the background image. It is all black except for the text. And of course the text is not on a transparent layer. Any ideas how I can create this effect with animated text? I've tried messing with transparency and overlay settings, nothing seems to work.
    Running latest version of Final Cut Studio...
    Thanks
    Dave

    Just bring the Motion (.motn) project into FCP and lay it over your clip.
    The QT you're exporting has to carry the alpha channel (animation codec, million+ colors), but don't waste your time/disk space with that. Just bring the motion project into FCP.
    Patrick

  • How can I create a photo shutter effect in FCP?

    How do I make an effect like a photo is being take during footage playback. I've done the effect before but when the picture "blinks" I want to see a white flash instead of a black one. Is there a way to change the color to white?

    If I'm understanding correctly, use "Dip to color dissolve" with adjustments to the percentage of opacity at the start/end and threshold should do it.
    Change the color from default black to white and adjust the length of the transition to simulate the quickness of the flash. Split the clip where you want the effect and add transition, set to 'edit on center'.
    Hope it helps

  • How can I create a Tilt-shift effect in Elements 13?

    I tried it as I did in Elements 9, but I probably forgot how. It won't work
    Anyone?

    Thks. I have the Dutch version and although in the Netherlands 'Tilt-shift' is a commonly used term, Adobe Netherlands decided to call it 'kantelen en verschuiven', which is a literal translation (very few will understand).

  • How can I create a Text-Input Field in BexAnalyzer for a Planning Function

    Hello,
    i want to create a pre calculation(contribution accounting) for Materials in BI-Integrated Planning. These Materials aren't in the master data. So I create a new Info Object for pre calculated materials with only a material-number as key and a text-description.
    Now I want to write a Exit-Function, which creates new materials in these Info Object. The user should start this function in a planning application in BexAnalyzer. There the user should have the possibility to enter a text-description for the new material. How can I create such a Text-Field in BexAnalyzer and how can I read this text filed in a planning function (exit).
    Thanks in advance

    Hi Jürgen,
    you can create a parameter for this in the exit function and a variable for the parameter. In BEx Analyzer then create a button for the planning function; in the button parameterization use VAR_NAME = , i.e. use an Excel formula here to get the value from an Excel input field.
    The command range should be some 'hidden area' in your Excel sheet.
    But may be you don't need this. Use a characteristic without master data. Then ensure that that the query uses the option 'key' as display. In new lines you can then enter the key, the system creates a SID on the fly (but the text table will not be updated). In this scenario you may take text also from the key. May be you can update the text table (online or in batch) by simply using function modules from function group RSNDI_MD (not released by SAP).
    But observere that the system in BI Planning reads only the active version, i.e. if you change something on the fly the changes may not be visible.
    Regards,
    Gregor

  • How can I create a christmas newsletter with iPhoto on my iMac

    How can I create a christmas text newsletter with added photos from iPhoto on my iMac

    Hi there Sebastian.cruzr,
    You may find the troubleshooting steps in the article below helpful.
    iOS: Troubleshooting Personal Hotspot
    http://support.apple.com/kb/ts2756
    USB troubleshooting
    If you're using USB to connect your computer to Personal Hotspot and can't connect to the Internet, check your computer's network settings. You may need to disconnect and reconnect the USB Ethernet interface.
    Select your operating system for instructions.
    Mac OS X
    Go to System Preferences > Network.
    Select the Ethernet adapter.
    Click the gear icon and choose Make Service Inactive.
    Choose Make Service Active.
    -Griff W. 

  • How can I create a text pop up window in my Pages document? I want text to pop up when the reader hovers his/her cursor over a certain word.

    How can I create a text pop up window in my Pages document? I want text to pop up when the reader hovers his/her cursor over a certain word in the document. I am teacher. So for example when a student came to word he/she did not know, if he/she hovered the cursor over the word, a defintion or other information would appear.  You can do this in Word using bookmarks/hyperlinks but I can't figure this out in Pages. I can link it to another point in my Pages document but I just need the text to pop up - not take the reader to another location.  THANK YOU!!!!!!

    Have you tried Word for Mac?
    You will need to test if links survive export or printing to .pdf
    Peter

  • How can I create an iridescent effect in a Photoshop 3D object?

    How can I create an iridescent effect in a Photoshop 3D object? I have searched everywhere for downloadable option for a mac with no luck. I'm working with CS6.

    NO way. Such stuff isn't even commonly available in many 3D programs becaus it's actually pretty advanced shader stuff...
    Mylenium

  • How can I create a form for users wherein the text field will expand to accommodate additional text?

    How can I create a form for users wherein the text field will expand to accommodate additional text?

    You need to use LiveCycle (PC Only) to create a dynamic form like that.
    The best you can do with Acrobat to view all of the text in a field is to set the field to multiline, and set the size to "Auto" (If you don't set the size to 'Auto', you can enter as much text as you wish, but the user will need to use the scrollbar to view all of the text.)

  • HOW CAN I CREATE A GROUP WITH MY CONTACTS FOR TEXTING

    HOW CAN I CREATE A GROUP WITH MY CONTACTS FOR TEXTING

    Olga, this is not a default feature in iPhone. You need a 3rd party application. I have created a free one, Easy Group, for group texting and group emailing.
    http://itunes.apple.com/fr/app/easy-group/id461469079?mt=8
    Rémi
    Note: I may receive some form of compensation, financial or otherwise,from my recommendation or link.

  • Cool effect..how can i create this effect on Motion 3?

    that's great.
    Someone please tell me how can i create this effect on motion 3?
    http://www.ayatoweb.com/aetips_e/ae17_mov05e.html
    thanks

    Use the bezier tool to create your shapes, give the shapes an Airbrush outline. Then apply a Write On behavior to each shape. Position the shapes in the timeline so they appear sequentially. To achieve the zooming out effect, you can either scale the whole group, or convert the group to 3D and use the camera to zoom out.

Maybe you are looking for

  • Power4 vs Intel Woodcrest & Clovertown

    Does anyone know how the Power4 chip (currently in G5's) compares specs-wise, with Intels Woodcrest (dual-core) or Clovertown (quad-core). Thanks for the info! Content edited by an Apple Discussions Host

  • Recording more than 2 tracks?

    I bought Logic Express 8 and an M-Audio Fast Track Ultra interface to record keyboard, vocal and guitar. The Fast Track Ultra is a 4 channel USB interface. I just tried to record the keyboard in stereo, and a vocal track at the same time. The problem

  • Buildspaces PDE_TRCKXSS_C with all the DCs Broken

    Hi my friends In the CBS I have the Buildspaces: PDE_TRCKXSS_D and PDE_TRCKXSS_C. In the PDE_TRCKXSS_D  not present any error, while the PDE_TRCKXSS_C appear all the DCs as Broken . In the CBS Buildspace Details PDE_TRCKXSS_C appears several SC witho

  • Where are my IPhoto pics on my MacBookPro.

    I'm on Maverick.  I thought I used to access them in a "Library" folder but I can't seem to locate them now.  I then tried to export an IPhoto folder to another location but all the dates of the pictures converted to the current date.  Can anyone tel

  • Serial number  for photoshop elements 7

    Hi , i 've got an old sony vaio with a license for photoshop elements 7 and premiere elements 7 , now i have bought a new laptop and i wand to install  adobe on it but i can not find the serial number  , i've found a serial but only with 20 numbers .