1

私は次のコードを持っています:

final Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView parent, View v, int position, long id) {

        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        Bitmap b = null;
        b=BitmapFactory.decodeResource(getResources(),*********);

        b.compress(CompressFormat.PNG, 0, outputStream);   
        AlertDialog.Builder builder = new AlertDialog.Builder(Edit.this);
        builder.setTitle("Comfirm");
        builder.setMessage("Do you want to choose this picture?");
        builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                                          image = outputStream.toByteArray();   

                  }                        
              });

ご覧のとおり*****、 int のようにする必要がありますandroid.R.drawble.icon。ユーザーが画像をクリックしたときに画像を保存したい。ユーザーがクリックしたときに画像を取得するにはどうすればよいですか?

4

2 に答える 2

0

AdapterView.getItemAtPosition(int position)は、 のその位置にあるオブジェクトを返しますAdapterView。このオブジェクトが何らかのものであると仮定した場合、ここでDrawableの回答を使用してを に変換できます。を取得したら、次の操作を実行してDrawableBitmapBitMapbyte[]

int size = bitmap.getWidth() * bitmap.getHeight();
ByteArrayOutputStream out = new ByteArrayOutputStream(size);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();}
byte[] x = out.toByteArray());

byte[]その後、sqlite に blob として保存できます。

于 2010-11-29T10:47:59.987 に答える
0
function createDatabase() 
{
       try{
            if(window.openDatabase){
                var shortName       =   'db_edentiti';
                var version         =   '1.0';
                var displayName     =   'Edentiti Information';
                var maxSize         =   65536; // in bytes
                db                  =   openDatabase(shortName, version, displayName, maxSize);
            }
       }catch(e){
           alert(e);
       }
    }

function executeQuery($query,callback){
    try{
        if(window.openDatabase) {

            db.transaction(
                    function(tx){
                        tx.executeSql($query,[],function(tx,result){
                            if(typeof(callback) == "function"){
                                callback(result);
                            }else{
                                if(callback != undefined){
                                    eval(callback+"(result)");
                                }
                            }

                        },function(tx,error){});
                    });
            return rslt;
        }
    }catch(e){}
}

function createTable()
{
        var sql = 'drop table image';
        executeQuery(sql);
        var sqlC = 'CREATE TABLE image (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, image BLOB )';
        executeQuery(sqlC);
    }
function insertValue()
{
    var img = document.getElementById('image');
    var sql = 'insert into image (name,image) VALUES ("sujeet","'+img+'")';
    executeQuery(sql,function(results){alert(results)});
}

    <input type="button" name='create' onClick="createDatabase()" value='Create Database'>
    <input type="button" name='create' onClick="createTable()" value='create table'>
    <input type="button" name='insert' onClick="insertValue()" value='Insert value'>
    <input type="button" name='select' onClick="showTable()" value='show table'>
    <input type="file" id="image" >
    <div result></div>

詳細情報と解決策については、以下のリンクを参照してください。

http://blog.developeronhire.com/create-sqlite-table-insert-into-sqlite-table/

ありがとうございました

于 2011-01-16T11:50:17.153 に答える