1
0
mirror of https://github.com/bspeice/itcs4180 synced 2024-11-14 03:18:12 -05:00
itcs4180/UNCCScavenger/src/edu/uncc/scavenger/BitmapAccess.java
tokugawa 782a31eb4d Added function to save images to storage and load them. Compass image
will now change to the location when you get close.
2014-04-19 23:02:52 -04:00

70 lines
1.5 KiB
Java

package edu.uncc.scavenger;
/*
* Bradlee Speice, Brandon Rodenmayer
* ITIS 4180
* UNCCScavenger (NinerFinder)
* CompassActivity.java
*/
//Reference: stackoverflow.com/questions/19978100/how-to-save-bitmap-on-internal-storage-download-from-internet
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
public class BitmapAccess
{
public static Bitmap loadBitmap(Context context, String picName)
{
Bitmap b = null;
FileInputStream fis;
try
{
fis = context.openFileInput(picName);
b = BitmapFactory.decodeStream(fis);
fis.close();
}
catch(FileNotFoundException e)
{
Log.d("BitmapAccess", "FileNotFound_Load");
}
catch(IOException e)
{
Log.d("BitmapAccess", "IOException_Load");
}
return b;
}
public static boolean saveBitmap(Context context, Bitmap b, String picName)
{
boolean saved = false;
FileOutputStream fos;
try
{
fos = context.openFileOutput(picName, Context.MODE_PRIVATE);
b.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
}
catch(FileNotFoundException e)
{
Log.d("BitmapAccess", "FileNotFound_Save");
}
catch(IOException e)
{
Log.d("BitmapAccess", "IOException_Save");
}
return saved;
}
}