Hi I have saved the the image as a blob in my SQLite database:
public void onCreate(SQLiteDatabase db) {
String sql = "create table " + DATABASE_TABLE + " ( " +
FIELD_ROW_ID + " integer primary key autoincrement , " +
FIELD_LNG + " double , " +
FIELD_LAT + " double , " +
FIELD_ZOOM + " text , " +
FIELD_IMAGE + " blob " +
" ) ";
.....
public Cursor getAllLocations(){
return mDB.query(DATABASE_TABLE, new String[] { FIELD_ROW_ID, FIELD_LAT , FIELD_LNG, FIELD_ZOOM, FIELD_IMAGE} , null, null, null, null, null, null);
}
And then in my Main Activity when loading the data from SQLite:
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
int locationCount = 0;
double lat=0;
double lng=0;
float zoom=0;
byte[] bt = null;
locationCount = arg1.getCount();
arg1.moveToFirst();
for(int i=0;i<locationCount;i++){
// Get the latitude
lat = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LAT));
lng = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LNG));
zoom = arg1.getFloat(arg1.getColumnIndex(LocationsDB.FIELD_ZOOM));
bt = arg1.getBlob(arg1.getColumnIndex(LocationsDB.FIELD_IMAGE));
thePoint = new LatLng(lat, lng);
drawMarker(thePoint);
arg1.moveToNext();
}
if(locationCount>0){
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat,lng)));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(zoom));
ImageView image = (ImageView) findViewById(R.id.marker_icon);
image.setImageBitmap(BitmapFactory.decodeByteArray(imageData, 0, imageData.length));
And when launching the app i can add the image, but when returning to the activity it crashes with this error:
01-04 10:51:03.995: E/AndroidRuntime(29156): at com.test.testmap(TestingMap.java:347)
01-04 10:51:03.995: E/AndroidRuntime(29156): at com.test.testmap.TestingMap.onLoadFinished(TestingMap.java:1)
01-04 10:51:03.995: E/AndroidRuntime(29156): at android.support.v4.app.LoaderManagerImpl$LoaderInfo.callOnLoadFinished(LoaderManager.java:427)
Now at line 347
this is the code that is there is this:
image.setImageBitmap(BitmapFactory.decodeByteArray(imageData, 0, imageData.length));
CREATING THE BYTE[]
baos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 100, baos);
imageData = baos.toByteArray();
Has anyone got an idea what i am doing wrong here? Thanks.
NOTE
at this line byte[] bt =null
i get a warning under bt saying: The value of the local variable bt is not used
but am not sure how to use it in my code when placing the image?
Aucun commentaire:
Enregistrer un commentaire