如何保存和放大器;删除黑莓风暴位图图像? [英] How to save & delete a Bitmap image in Blackberry Storm?

查看:197
本文介绍了如何保存和放大器;删除黑莓风暴位图图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现成的位图图像。现在,我要救&安培;删除它。我米做它像..

I have a ready Bitmap image. Now I want to save & delete it. I m doing it like..

FileConnection fconn = (FileConnection)Connector.open("file:///store/home/user/StoredBitmap/"+picIndex+".bmp",Connector.READ_WRITE);

        if(!fconn.exists())
            fconn.create();

        OutputStream out = fconn.openOutputStream();

       if(image == null)
            System.out.println("    image null  ");
       else
       {
            out.write(byte[]);
            out.close();
       }

        fconn.close();

有关黑莓风暴设备和放大器;模拟器,给予,而不是哪条路径

For Blackberry Storm device & simulator, which path to give instead of

"file:///store/home/user/StoredBitmap/"+picIndex+".bmp"

我有一个创建的位图。在OutputStream的,怎么写呢?

I have a created Bitmap. In outputStream, how to write it?

我米使用黑莓4.7(版本:4.7.0.41)。在它的模拟器,如何保存位图?我米做的黑莓风暴。

I m using Blackberry 4.7 (Version: 4.7.0.41). In its simulator, how to save the Bitmap? I m doing it for Blackberry Storm.

&安培;删除该位图,我们可以使用File类或我们所使用类的FileConnection?

& for deleting that Bitmap, can we use File class or we've to use FileConnection class?

推荐答案

看看这(写/读/删除)

Take a look at this (write/read/delete)

class Scr extends MainScreen implements FieldChangeListener {
    ButtonField mWrite;
    ButtonField mRead;
    ButtonField mDelete;

    String mFileName = System.getProperty("fileconn.dir.photos") 
        	+ "test.bmp";

    public Scr() {
    	mWrite = new ButtonField("Write file", 
        	    	ButtonField.CONSUME_CLICK);
    	add(mWrite);
    	mWrite.setChangeListener(this);

    	mRead = new ButtonField("Read file", 
        	    	ButtonField.CONSUME_CLICK);
    	add(mRead);
    	mRead.setChangeListener(this);

    	mDelete = new ButtonField("Delete file", 
        	    	ButtonField.CONSUME_CLICK);
    	add(mDelete);
    	mDelete.setChangeListener(this);
    }

    public void fieldChanged(Field field, int context) {
    	if (mWrite == field) {
    		byte[] bytes = new byte[] { 1, 2, 1, 1 };
    		writeFile(bytes, mFileName);
    		Dialog.inform("File " + mFileName + " saved");
    	} else if (mRead == field) {
    		byte[] bytes = readFile(mFileName);
    		if (null != bytes)
    			Dialog.inform("File " + mFileName + " opened");
    	} else if (mDelete == field) {
    		deleteFile(mFileName);
    		Dialog.inform("File " + mFileName + " deleted");
    	}

    }

    private void writeFile(byte[] data, String fileName) {
    	FileConnection fconn = null;
    	try {
    		fconn = (FileConnection) Connector.open(fileName,
    				Connector.READ_WRITE);
    	} catch (IOException e) {
    		System.out.print("Error opening file");
    	}

    	if (fconn.exists())
    		try {
    			fconn.delete();
    		} catch (IOException e) {
    			System.out.print("Error deleting file");
    		}
    	try {
    		fconn.create();
    	} catch (IOException e) {
    		System.out.print("Error creating file");
    	}
    	OutputStream out = null;
    	try {
    		out = fconn.openOutputStream();
    	} catch (IOException e) {
    		System.out.print("Error opening output stream");
    	}

    	try {
    		out.write(data);
    	} catch (IOException e) {
    		System.out.print("Error writing to output stream");
    	}

    	try {
    		fconn.close();
    	} catch (IOException e) {
    		System.out.print("Error closing file");
    	}
    }

    private byte[] readFile(String fileName) {
    	byte[] result = null;
    	FileConnection fconn = null;
    	try {
    		fconn = (FileConnection) Connector.open(fileName, 
        	    	    	Connector.READ);
    	} catch (IOException e) {
    		System.out.print("Error opening file");
    	}

    	if (!fconn.exists()) {
    		Dialog.inform("file not exist");
    	} else {

    		InputStream in = null;
    		ByteVector bytes = new ByteVector();
    		try {
    			in = fconn.openInputStream();
    		} catch (IOException e) {
    			System.out.print("Error opening input stream");
    		}

    		try {
    			int c = in.read();
    			while (-1 != c) {
    				bytes.addElement((byte) c);
    				c = in.read();
    			}
    			result = bytes.getArray();
    		} catch (IOException e) {
    			System.out.print("Error reading input stream");
    		}

    		try {
    			fconn.close();
    		} catch (IOException e) {
    			System.out.print("Error closing file");
    		}
    	}
    	return result;
    }

    private void deleteFile(String fileName) {
    	FileConnection fconn = null;
    	try {
    		fconn = (FileConnection) Connector.open(fileName,
    				Connector.READ_WRITE);
    	} catch (IOException e) {
    		System.out.print("Error opening file");
    	}

    	if (!fconn.exists()) {
    		Dialog.inform("file not exist");
    	} else {
    		try {
    			fconn.delete();
    		} catch (IOException e1) {
    			System.out.print("Error deleting file");
    		}

    		try {
    			fconn.close();
    		} catch (IOException e) {
    			System.out.print("Error closing file connection");
    		}
    	}
    }

这篇关于如何保存和放大器;删除黑莓风暴位图图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆