📄 scrollcanvas.java
字号:
}
/*
* 响应按键事件,设置按键标志
*
*/
public synchronized void keyPressed(int keyCode) {
int gameKey = getGameAction(keyCode);
if ((gameKey == UP) || (keyCode == KEY_NUM2)) {
this.upKeyPressed = true;
} else if ((gameKey == LEFT) || (keyCode == KEY_NUM4)) {
this.leftKeyPressed = true;
} else if ((gameKey == RIGHT) || (keyCode == KEY_NUM6)) {
this.rightKeyPressed = true;
} else if ((gameKey == DOWN) || (keyCode == KEY_NUM8)) {
this.downKeyPressed = true;
} else if (keyCode == KEY_NUM1) {
this.num1KeyPressed = true;
} else if (keyCode == KEY_NUM3) {
this.num3KeyPressed = true;
} else if (keyCode == KEY_NUM5) {
this.num5keyPressed = true;
}
}
/*
* 被KeyRepeatTask类周期地调用来重复移动图片或者改变背景色,这个功能仅仅在移动设备不支持重复按键事件的时候才被激活
*
*/
public synchronized void repeatImageMove()
{
if (upKeyPressed)
imgY += MOVE_IMAGE_OFF;
else if (downKeyPressed)
imgY -= MOVE_IMAGE_OFF;
else if (leftKeyPressed)
imgX -= MOVE_IMAGE_OFF;
else if (rightKeyPressed)
imgX += MOVE_IMAGE_OFF;
else if (this.num1KeyPressed) {
changeBgValue('1');
} else if (this.num3KeyPressed) {
changeBgValue('3');
} else if (this.num5keyPressed) {
changeBgValue('5');
}
repaint();
serviceRepaints();
}
public void run() {
// System.out.println("Run IN");
int stopIndex = 0;
while (mTrucking) {
if (mUpdate) {
// 每循环一次改变一次alpha值 255=不透明, 0=透明
if (mAlpha >= 255) {
stopIndex++;
// System.out.println(stopIndex);
changeAlphaOff = changeAlphaOff * -1;
} else if (mAlpha <= 0) {
changeAlphaOff = changeAlphaOff * -1;
}
mAlpha += changeAlphaOff;
// 使用ImageEffect里的blend方法来改变alphi值并且生成一个新的图象
ImageEffect.blend(rawInt, mAlpha);
image = Image.createRGBImage(rawInt, this.image.getWidth(),
this.image.getHeight(), true);
repaint();
if (stopIndex == 2) {
// System.out.println(this.mAlpha);
// System.out.println(this.changeAlphaOff);
this.mAlpha = 255;
this.changeAlphaOff = 15;
break;
}
// mUpdate = false;
}
}
ImageEffect.blend(rawInt, mAlpha);
image = Image.createRGBImage(rawInt, this.image.getWidth(), this.image
.getHeight(), true);
repaint();
// System.out.println("Run OUT");
}
private void fading() {
// *******************************************************************
try {
// 获得图像的ARGB数据,存储在rawInt里
rawInt = new int[this.image.getWidth() * image.getHeight()];
this.image.getRGB(rawInt, 0, image.getWidth(), 0, 0, image
.getWidth(), image.getHeight());
Thread t = new Thread(this);
t.start();
} catch (OutOfMemoryError e) {
ImageAlbum.showAlert("图像尺寸太大,不能完成此操作.");
// e.printStackTrace();
}
// *******************************************************************
}
private String getNextUrl() {
String url = ImageAlbum.getCurrentUrl();
// currentUrl = SUB_URL+i+"/th_001.jpg";
String nextUrl = "";
String prefixUrl = url.substring(0, url.length() - 6);
String tmp1 = url.substring(prefixUrl.length());
String extension = tmp1.substring(2);
String number = (tmp1).substring(0, tmp1.length() - 4);
int num = Integer.parseInt(number);
num++;
if (num < 10) {
nextUrl = prefixUrl + "0" + num + extension;
} else {
nextUrl = prefixUrl + num + extension;
}
// System.out.println(prefixUrl);
// System.out.println(number);
// System.out.println(extension);
// System.out.println("number is :" + num);
// System.out.println(nextUrl);
// 设置当前的Url
ImageAlbum.setCurrentUrl(nextUrl);
return nextUrl;
}
private String getPreviousUrl() {
String url = ImageAlbum.getCurrentUrl();
String previousUrl = "";
String prefixUrl = url.substring(0, url.length() - 6);
String tmp1 = url.substring(prefixUrl.length());
String extension = tmp1.substring(2);
String number = (tmp1).substring(0, tmp1.length() - 4);
int num = Integer.parseInt(number);
num--;
if (num < 10) {
previousUrl = prefixUrl + "0" + num + extension;
} else {
previousUrl = prefixUrl + num + extension;
}
// System.out.println(prefixUrl);
// System.out.println(number);
// System.out.println(extension);
// System.out.println("number is :" + num);
// System.out.println(previousUrl);
// 设置当前的Url
ImageAlbum.setCurrentUrl(previousUrl);
return previousUrl;
}
public void commandAction(Command c, Displayable d) {
if (c == this.nextCommand) {
if (ImageAlbum.getCurrentUrl().length() < 5) {
// 从RMS里读取
int index = Integer.parseInt(ImageAlbum.getCurrentUrl());
//System.out.println(index + 1);
Image img = ImagePersistence.load(index + 1);
if (img != null) {
ImageAlbum.setCurrentUrl("" + (index + 1));
this.image = img;
ImageAlbum.getDisplay().setCurrent(this);
} else {
ImageAlbum.showAlert("已经达到第一张/最后一张图片.");
}
} else {
HttpWaitForm waitForm = new HttpWaitForm(getNextUrl());
ImageAlbum.setPreviousForm(this);
ImageAlbum.setCurrentForm(waitForm);
ImageAlbum.getDisplay().setCurrent(waitForm);
}
} else if (c == this.perviousCommand) {
if (ImageAlbum.getCurrentUrl().length() < 5) {
// 从RMS里读取
int index = Integer.parseInt(ImageAlbum.getCurrentUrl());
Image img = ImagePersistence.load(index - 1);
if (img != null) {
ImageAlbum.setCurrentUrl("" + (index - 1));
this.image = img;
ImageAlbum.getDisplay().setCurrent(this);
} else {
ImageAlbum.showAlert("已经达到第一张/最后一张图片.");
}
} else {
HttpWaitForm waitForm = new HttpWaitForm(getPreviousUrl());
ImageAlbum.setPreviousForm(this);
ImageAlbum.setCurrentForm(waitForm);
ImageAlbum.getDisplay().setCurrent(waitForm);
}
} else if (c == turn90Command) {
// 我实现的方法在图形变得很大时很容易就造成了内存溢出,呵呵,还是用J2ME自己的吧
// 我估计它是底层实现的
// this.image = ImageEffect.turn90(this.image);
this.image = Image.createImage(this.image, 0, 0, this.image
.getWidth(), this.image.getHeight(), Sprite.TRANS_ROT90);
repaint();
} else if (c == turn180Command) {
// 我实现的方法在图形变得很大时很容易就造成了内存溢出,呵呵,还是用J2ME自己的吧
// 我估计它是底层实现的
// this.image = ImageEffect.turn180(this.image);
this.image = Image.createImage(this.image, 0, 0, this.image
.getWidth(), this.image.getHeight(), Sprite.TRANS_ROT180);
repaint();
} else if (c == this.horizontalMirrorCommand) {
// 我实现的方法在图形变得很大时很容易就造成了内存溢出,呵呵,还是用J2ME自己的吧
// 我估计它是底层实现的
// this.image = ImageEffect.horizontalMirror(this.image);
this.image = Image.createImage(this.image, 0, 0, this.image
.getWidth(), this.image.getHeight(), Sprite.TRANS_ROT180);
this.image = Image.createImage(this.image, 0, 0, this.image
.getWidth(), this.image.getHeight(), Sprite.TRANS_MIRROR);
repaint();
} else if (c == this.verticalMirrorCommand) {
// 我实现的方法在图形变得很大时很容易就造成了内存溢出,呵呵,还是用J2ME自己的吧
// 我估计它是底层实现的
// this.image = ImageEffect.verticalMirror(this.image);
this.image = Image.createImage(this.image, 0, 0, this.image
.getWidth(), this.image.getHeight(), Sprite.TRANS_MIRROR);
repaint();
} else if (c == zoomInCommand) {
this.image = ImageEffect.zoomInImage(this.image);
repaint();
} else if (c == zoomOutCommand) {
this.image = ImageEffect.zoomOutImage(this.image);
repaint();
} else if (c == saveCommand) {
if (ImagePersistence.save(this.image, "pic")) {
ImageAlbum.showAlert("保存成功");
} else {
ImageAlbum.showAlert("不能保存,可能图像尺寸太大");
}
} else if (c == thumbNailsCommand) {
this.image = ImageEffect.createThumbnail(this.image);
repaint();
} else if (c == this.fadingCommand) {
fading();
}
// else if (c == this.saveBgCommand) {
// }
else if (c == this.reverseRGBCommand) {
this.image = ImageEffect.reverseRGB(this.image);
} else if (c == this.grayRGBCommand) {
this.image = ImageEffect.grayRGB(this.image);
} else if (c == this.grayRGB2Command) {
this.image = ImageEffect.grayRGB2(this.image);
} else if (c == this.darkleCommand) {
this.darkleEnd -= 15;
if (this.darkleEnd < 0) {
this.darkleEnd = 0;
}
// System.out.println(this.darkleEnd);
this.image = ImageEffect.lightenessRGB(this.originalImage, 0,
this.darkleEnd);
} else if (c == this.whitenCommand) {
this.darkleEnd += 15;
if (this.darkleEnd > 255) {
this.darkleEnd = 255;
}
// System.out.println(this.darkleEnd);
this.image = ImageEffect.lightenessRGB(this.originalImage, 0,
this.darkleEnd);
}
else if (c == memoryCommand) {
ImageAlbum.showAlert("系统最大Heap内存为:"
+ Runtime.getRuntime().totalMemory() + "\n可用内存为:"
+ Runtime.getRuntime().freeMemory());
} else if (c == backCommand) {
ImageAlbum.getDisplay().setCurrent(ImageAlbum.getList());
}
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public Image getOriginalImage() {
return originalImage;
}
public void setOriginalImage(Image originalImage) {
this.originalImage = originalImage;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -