⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fonteffect.java

📁 索爱系统字体特效制作 ,索爱系统字体特效制作
💻 JAVA
字号:
/***************************************************************************** Description: Changes the layout of a text draw on a image.               - Color               - Monospace               - Background masking Created By: Oscar Vivall  @file        FontEffect.java COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2004. The software is the copyrighted work of Sony Ericsson Mobile Communications AB. The use of the software is subject to the terms of the end-user license  agreement which accompanies or is included with the software. The software is  provided "as is" and Sony Ericsson specifically disclaim any warranty or  condition whatsoever regarding merchantability or fitness for a specific  purpose, title or non-infringement. No warranty of any kind is made in  relation to the condition, suitability, availability, accuracy, reliability,  merchantability and/or non-infringement of the software provided herein.*****************************************************************************/import javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class FontEffect {    public static final int EFFECT_MASK = 1,                             EFFECT_MONOSPACE = 2,                             EFFECT_COLOR = 4;    private Font font;    private int textWidth, textHeight; // this will be the size of the image.    private Image fontImage;    private Graphics graphics;        private int fontColor = 0x00;    private int backgroundColor = 0xFFFFFFFF;    private int effect = 0;    private String text;    public FontEffect(String s){        font = Font.getDefaultFont();        text = s;                createImage();    }    public void applyEffect(int e){        System.out.println("applyEffect:" + e);        effect = e;        doEffect();    }    public void setColor(int argb){        System.out.println("setColor");        fontColor = argb;        doEffect();    }    public void setFont(Font f){        font = f;        createImage();        doEffect();    }    public Image getImage(){        return fontImage;    }    public void render(Graphics g, int x, int y, int anchor){        g.drawImage(fontImage, x, y, anchor);    }    private void createImage(){                textWidth = font.stringWidth(text);        textHeight = font.getHeight();                fontImage = null;        fontImage = Image.createImage(textWidth, textHeight); // image with a white background.        backgroundColor = 0xFFFFFFFF;        graphics = fontImage.getGraphics();        graphics.setFont(font);        graphics.setColor(fontColor);        graphics.drawString(text, 0, 0, 0);    }    private void doEffect(){        if((effect & EFFECT_MONOSPACE) == EFFECT_MONOSPACE){            monoSpaceEffect();        }        if((effect & EFFECT_MASK) == EFFECT_MASK){            maskEffect();        }        if((effect & EFFECT_COLOR) == EFFECT_COLOR){            colorEffect();        }    }    private void monoSpaceEffect(){        System.out.println("monoSpaceEffect");        int charWidth = font.charWidth('W');        textWidth = charWidth * text.length();        fontImage = null;        fontImage = Image.createImage(textWidth, textHeight); // image with a white background.        backgroundColor = 0xFFFFFFFF;        graphics = fontImage.getGraphics();        graphics.setFont(font);        graphics.setColor(0x00);        for(int i=0; i<text.length(); i++){            graphics.drawChar(text.charAt(i),i*charWidth + charWidth/2, 0, Graphics.TOP | Graphics.HCENTER);        }    }    private void maskEffect(){        System.out.println("maskEffect");        int []data = new int[fontImage.getWidth() * fontImage.getHeight()];        fontImage.getRGB(data, 0, fontImage.getWidth(), 0, 0, fontImage.getWidth(), fontImage.getHeight());        for(int i=0; i<data.length; i++){            if(data[i]==backgroundColor){                data[i] = (data[i]&0x00FFFFFF);            }        }        backgroundColor = (backgroundColor & 0x00FFFFFF);        fontImage = null;        fontImage = Image.createRGBImage(data, textWidth, textHeight, true);    }        /*     *  Change the color of the font from the selected color fading to black.     */    private void colorEffect(){        System.out.println("colorEffect");        int []data = new int[fontImage.getWidth() * fontImage.getHeight()];        fontImage.getRGB(data, 0, fontImage.getWidth(), 0, 0, fontImage.getWidth(), fontImage.getHeight());        int newColor = fontColor;        int r = (fontColor & 0x00FF0000)>>16;        int g = (fontColor & 0x0000FF00)>>8;        int b = (fontColor & 0x000000FF);        int offsetR = r/fontImage.getHeight();        int offsetG = g/fontImage.getHeight();        int offsetB = b/fontImage.getHeight();        for(int i=0; i<data.length; i++){            if(data[i] != backgroundColor){                data[i] = newColor;            }            if(i%textWidth == 0){                if(r>offsetR)                    r -= offsetR;                if(g>offsetG)                    g -= offsetG;                if(b>offsetB)                    b -= offsetB;                newColor = 0xFF000000;                newColor += (r<<16);                newColor += (g<<8);                newColor += b;            }        }        fontImage = null;        fontImage = Image.createRGBImage(data, textWidth, textHeight, true);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -