选择显示字体大小

手机上实现任意角度翻转算法[适用任何机型]

web2.0package rorate;

import javax.microedition.lcdui.graphics;

/
* 图片任意角度翻转算法
* 同时实现了nokia特有api
* author. bb
* sprite.java
*
*
*/

public class sprite {

/** sin table **/

public final static int sin_table[] =

{

0, 4, 8, 13, 17, 22, 26, 31, 35, 39,

44, 48, 53, 57, 61, 65, 70, 74, 78, 83,

87, 91, 95, 99, 103, 107, 111, 115, 119, 123,

127, 131, 135, 138, 142, 146, 149, 153, 156, 160,

163, 167, 170, 173, 177, 180, 183, 186, 189, 192,

195, 198, 200, 203, 206, 208, 211, 213, 216, 218,

220, 223, 225, 227, 229, 231, 232, 234, 236, 238,

239, 241, 242, 243, 245, 246, 247, 248, 249, 250,

251, 251, 252, 253, 253, 254, 254, 254, 254, 254,

255, 254, 254, 254, 254, 254, 253, 253, 252, 251,

251, 250, 249, 248, 247, 246, 245, 243, 242, 241,

239, 238, 236, 234, 232, 231, 229, 227, 225, 223,

220, 218, 216, 213, 211, 208, 206, 203, 200, 198,

195, 192, 189, 186, 183, 180, 177, 173, 170, 167,

163, 160, 156, 153, 149, 146, 142, 138, 135, 131,

127, 123, 119, 115, 111, 107, 103, 99, 95, 91,

87, 83, 78, 74, 70, 65, 61, 57, 53, 48,

44, 39, 35, 31, 26, 22, 17, 13, 8, 4,

0, -4, -8, -13, -17, -22, -26, -31, -35, -39,

-44, -48, -53, -57, -61, -65, -70, -74, -78, -83,

-87, -91, -95, -99, -103, -107, -111, -115, -119, -123,

-127, -131, -135, -138, -142, -146, -149, -153, -156, -160,

-163, -167, -170, -173, -177, -180, -183, -186, -189, -192,

-195, -198, -200, -203, -206, -208, -211, -213, -216, -218,

-220, -223, -225, -227, -229, -231, -232, -234, -236, -238,

-239, -241, -242, -243, -245, -246, -247, -248, -249, -250,

-251, -251, -252, -253, -253, -254, -254, -254, -254, -254,

-255, -254, -254, -254, -254, -254, -253, -253, -252, -251,

-251, -250, -249, -248, -247, -246, -245, -243, -242, -241,

-239, -238, -236, -234, -232, -231, -229, -227, -225, -223,

-220, -218, -216, -213, -211, -208, -206, -203, -200, -198,

-195, -192, -189, -186, -183, -180, -177, -173, -170, -167,

-163, -160, -156, -153, -149, -146, -142, -138, -135, -131,

-127, -123, -119, -115, -111, -107, -103, -99, -95, -91,

-87, -83, -78, -74, -70, -65, -61, -57, -53, -48,

-44, -39, -35, -31, -26, -22, -17, -13, -8, -4

};

/** 透明 **/
public static int transparent = 0;

/** 不透明 **/
public static int opaque = 15;

/**
* 像素值
* 包含动画帧,主下标标识动画帧数,副下标的值代表像素值
*/
public short pixels[][];

/*
* 精灵的宽度
* 该版本默认精灵各个帧的宽度一样大小
*/
public short width;

/*
* 精灵的高度
* 该版本默认精灵各个帧的高度一样大小
*/
public short height;

/*
* 动画帧数
*/
public byte numofframe;

/*
* 当前动画帧数
*/
public int curframe;

/*
* 构造函数
* 确保传入的各个值为合理的值
* 使用的话请自己做判断
* @param _pixels 动画的像素值
* @param _width 宽度
* @param _height 高度
*/
public sprite(short[][] _pixels, short _width, short _height){

pixels = _pixels;

width = _width;

height = _height;

numofframe = (byte)_pixels.length;

curframe = 0;

}

/*

* 构造函数

*/

public sprite(){

}

/*
* 投影
* @param cdata
* @param l
* @param i1
* @param j1
* @param k1
* @return
*/
private final short project(short cdata[], int l, int i1, int j1, int k1) {

int j3 = (j1 & 0xffff) >> 8;

int k3 = (k1 & 0xffff) >> 8;

int l3 = (256 - j3) * (256 - k3);

int i4 = j3 * (256 - k3);

int j4 = (256 - j3) * k3;

int k4 = j3 * k3;

int l2 = j1 >> 16;

int i3 = k1 >> 16;

l2 %= l;

i3 %= i1;

i3 *= l;

short word0 = cdata[l2 + i3];

short word2 = cdata[(l2 + (i3 + l)) % (cdata.length - 1)];

l2 = ++l2 % l;

short word1 = cdata[l2 + i3];

short word3 = cdata[(l2 + (i3 + l)) % (cdata.length - 1)];

int l1 = word0 >> 12 & 0xf;

int i2 = word1 >> 12 & 0xf;

int j2 = word2 >> 12 & 0xf;

int k2 = word3 >> 12 & 0xf;

int k5 = l1 * l3 + i2 * i4 + j2 * j4 + k2 * k4 >> 16;

l1 = word0 >> 8 & 0xf;

i2 = word1 >> 8 & 0xf;

j2 = word2 >> 8 & 0xf;

k2 = word3 >> 8 & 0xf;

int l4 = l1 * l3 + i2 * i4 + j2 * j4 + k2 * k4 >> 16;

l1 = word0 >> 4 & 0xf;

i2 = word1 >> 4 & 0xf;

j2 = word2 >> 4 & 0xf;

k2 = word3 >> 4 & 0xf;

int i5 = l1 * l3 + i2 * i4 + j2 * j4 + k2 * k4 >> 16;

l1 = word0 & 0xf;

i2 = word1 & 0xf;

j2 = word2 & 0xf;

k2 = word3 & 0xf;

int j5 = l1 * l3 + i2 * i4 + j2 * j4 + k2 * k4 >> 16;

return (short) ((k5 << 12) + (l4 << 8) + (i5 << 4) + j5);

&#125;

/*
* 翻转
* @param count 在360度内翻转的个数
* @return 返回一个翻转后的精灵
*/
public sprite rotate(int count) &#123;

sprite sprite = new sprite();

short radius = 30;

if (width == 40 && height == 40)

radius = 57;

else if (width == 8 && height == 8)

radius = 12;

else if (width == 6 && height == 12)

radius = 14;

else if (width == 24 && height == 24)

radius = 34;

else if (width == 26 && height == 26)

radius = 27;

else if (width == 8 && height == 15)

radius = 17;

else if (width == 10 && height == 16)

radius = 19;

else if (width == 11 && height == 15)

radius = 19;

else
system.out.println("wrong size: " + width + " " + width + " "

+ count);

sprite.width = radius;

sprite.height = radius;

sprite.numofframe = (byte)count;

sprite.pixels = new short[count][];

for (int j1 = 0; j1 < count; j1++) &#123;

sprite.pixels[j1] = new short[sprite.width * sprite.height];

int k1 = j1 * (360 / count);

short l1 = width;

short i2 = height;

width = sprite.width;

height = sprite.height;

int j2 = width / 2;

int k2 = l1 / 2;

int l2 = i2 / 2;

int i3 = sin_table[k1 % 360] << 8;

int j3 = sin_table[(k1 + 90) % 360] << 8;

int k4 = 0;

int i4 = -j2 * j3;

int j4 = -j2 * i3;

for (int l4 = 0; l4 < sprite.pixels[j1].length; l4++)

sprite.pixels[j1][l4] = (short) (transparent << 12);

for (int i5 = 0; i5 < height; i5++) &#123;

int k3 = -j2 * j3;

int l3 = -j2 * i3;

for (int j5 = 0; j5 < width; j5++) &#123;

//x

int k5 = (k3 - j4 >> 16) + k2;

//y

int l5 = (i4 + l3 >> 16) + l2;

if (k5 >= 0 && l5 >= 0 && l5 < i2 && k5 < l1)

sprite.pixels[j1][k4] = project(pixels[0], l1, i2,

(k3 - j4) + (k2 << 16), i4 + l3 + (l2 << 16));

k3 += j3;

l3 += i3;

k4++;

&#125;

i4 += j3;

j4 += i3;

k4 -= width;

k4 += sprite.width;

&#125;

height = i2;

width = l1;

&#125;

return sprite;

&#125;

/*
* 绘制精灵
* 在这里实现了nokia的特有api
* 大家可以扩展该方法
* @param g
* @param x
* @param y
* @param manipulate
*/
public void draw(graphics g, int x, int y, int manipulate) &#123;

drawpixels(g, true, 0, width, x, y, width,

height, manipulate, 4444);

&#125;

public void drawpixels(graphics g, boolean transparency,

int offset, int scanlength, int x, int y, int width, int height,

int manipulation, int format) &#123;

int l1 = map2manipulation(manipulation);

int j1;

int k1;

if ((l1 & 4) != 0) &#123;

j1 = height;

k1 = width;

&#125; else &#123;

j1 = width;

k1 = height;

&#125;

short newpixels[] = new short [j1 * k1];

if(manipulation == 0)&#123;

newpixels = pixels[curframe];

&#125;

else
for (int i2 = 0; i2 < k1; i2++) &#123;

for (int j2 = 0; j2 < j1; j2++) &#123;

int j = j2;

int k = i2;

if ((l1 & 1) != 0)

j = j1 - 1 - j;

if ((l1 & 2) != 0)

k = k1 - 1 - k;

if ((l1 & 4) != 0) &#123;

int k2 = j;

j = k;

k = k2;

&#125;

newpixels[j1 * i2 + j2] = pixels[curframe][width * k + j];

&#125;

&#125;

int off = offset;

int vw = x + j1;

int vh = y + k1;

for(int idy = y; idy < vh; idy++)&#123;

int voff = off;

for(int idx = x; idx < vw; idx++)&#123;

short pixel = newpixels[voff++];

int k3 = idx;

for(; idx < vw - 1 && newpixels[voff] == pixel; voff++)

idx++;

if((pixel >> 12 & 0xff) != 0)

&#123;

int l3 = 0xf0 & pixel << 4;

l3 = 0xf000 & pixel << 8;

l3 = 0xf00000 & pixel << 12;

g.setcolor(l3);

g.drawline(k3, idy, idx, idy);

&#125;

&#125;

off += j1;

&#125;

&#125;

private static int map2manipulation(int i) throws illegalargumentexception &#123;

int j = 0;

if ((i & 0x2000) != 0)

j ^= 1;

if ((i & 0x4000) != 0)

j ^= 2;

switch (i & 0xffff9fff) &#123;

case 90: // 'z'

j ^= 6;

break;

case 180:

j ^= 3;

break;

case 270:

j ^= 5;

break;

default:

throw new illegalargumentexception();

case 0: // '\0'

break;

&#125;

return j;

&#125;

&#125;


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons