📄 imagesaveform.java
字号:
/*****************************************************************************
Description: ImageSaveForm
* The ImageSaveform contains a ImageItem, that is a down scaled version of the snapshot.
* It also contains a textfield to enter the filename which throws e picture should be
* saved as.
Created By: Johan Kateby
@file ImageSaveForm.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.lcdui.*;
import java.util.*;
public class ImageSaveForm extends Form implements FileActionInvoker, CommandListener{
private ImageItem imageItem;
private TextField tf_fileName, tf_directory;
private Command editCommand, saveCommand, backCommand;
private StringItem si_homeDir;
private Displayable next;
private final byte[] imByte;
private FileAction fileAction;
Image image;
/** Creates a new instance of ImageSaveForm */
public ImageSaveForm(byte[] imByte, Displayable next) {
super("INFO:");
fileAction = new FileAction(this);
this.imByte=imByte;
this.next=next;
saveCommand = new Command("Save",Command.SCREEN,1);
backCommand = new Command("Back",Command.SCREEN,1);
image = Image.createImage(imByte, 0, imByte.length);
imageItem = new ImageItem("", PropertyClass.scaleDownImage(image, 0.25), Item.LAYOUT_RIGHT, "pic");
imageItem.setLayout(Item.LAYOUT_LEFT);
tf_fileName = new TextField("save picture as", "", 13, 0);
tf_directory = new TextField("", "Dir"+PropertyClass.HOME_DIR, 20, 0);
this.addCommand(saveCommand);
this.addCommand(backCommand);
this.setCommandListener(this);
this.append(imageItem);
this.append(tf_fileName);
this.append(tf_directory);
}
public void commandAction(Command c, Displayable s){
if (c==saveCommand)
{
// If the user wants to save the snapshot we start a new thread
// and use the fileAction object to save the snapshot as a file
// the fileAction object will call the fileSavedComplete method when finished.
final String fileName=tf_fileName.getString();
if(fileName!="")
new Thread(new Runnable() {
public void run() {
fileAction.saveFile(PropertyClass.HOME_DIR+fileName+".jpg",imByte );
}
}).start();
}
if (c==backCommand)
{
System.out.println("BACK");
FileConnectionDemoMidlet.display.setCurrent(next);
}
}
public void updateDirList(Enumeration CurrentDirEnum, boolean isRoot){}
public void ImageReceived(Image image){}
// This method is called by the FileAction object when it is finished with saving
// content to a file
public void fileSavedComplete(String msg)
{
this.setTitle("INFO: "+msg);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -