I have created an app using SPenSdk libraries. My app simply open an canvasView
and I saved that canvas view as an image in the sd card. Now problems arise when the user removes it sd card from the devices. At that time when I run my app it crashes because it is unable to find images for loading. So is there any way in which I can save my images created using canvas view in such a way that it will be my part of the app. so the removing of sd card doesn't affect the app.
Code For Saving Images In SdCard
public class CanvasActivity extends Activity
{
public static final String DEFAULT_APP_IMAGEDATA_DIRECTORY = "/mnt/sdcard/SmemoExample";
private File m_Folder = null;
private String m_FileName;
public static final String SAVED_FILE_EXTENSION = "png";
public static final String EXTRA_IMAGE_PATH = "path";
public static final String EXTRA_IMAGE_NAME = "filename";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
m_Folder = new File(DEFAULT_APP_IMAGEDATA_DIRECTORY);
m_FileName = getIntent().getStringExtra(EXTRA_IMAGE_NAME);
loadCanvas(m_FileName);
}
public boolean saveCanvas()
{
byte[] buffer = m_CanvasView.getData();
if (buffer == null)
return false;
if (!(m_Folder.exists()))
m_Folder.mkdirs();
String savePath = null;
if(m_FileName == null)
{
savePath = m_Folder.getPath() + '/' + UtilitiesActivity.getUniqueFilename(m_Folder, "image", SAVED_FILE_EXTENSION);
}
else
{
savePath = m_Folder.getPath() + '/' + m_FileName;
}
if (UtilitiesActivity.writeBytedata(savePath, buffer))
return true;
else
return false;
}
public boolean loadCanvas(String fileName)
{
String loadPath = m_Folder.getPath() + '/' + fileName;
byte[] buffer = UtilitiesActivity.readBytedata(loadPath);
if (buffer == null)
return false;
m_CanvasView.setData(buffer);
return true;
}
private CanvasView.OnHistoryChangeListener historyChangeListener = new CanvasView.OnHistoryChangeListener()
{
@Override
public void onHistoryChanged(boolean bUndoable, boolean bRedoable)
{
m_UndoButton.setEnabled(bUndoable);
m_RedoButton.setEnabled(bRedoable);
}
};
CanvasView.InitializeFinishListener mInitializeFinishListener = new CanvasView.InitializeFinishListener() {
@Override
public void onFinish() {
Bitmap bg = BitmapFactory.decodeResource(getResources(), R.drawable.canvas_bg);
m_CanvasView.setBackgroundImage(bg);
bg.recycle();
}
};
}
The issue isn't database or non database the issue is WHERE are your images. There's limited space ON the device, but if you don't want to store images on the sdcard you should just store them on the device's onboard memory. Stuffing them into database blobs doesn't help you here (actually, it just makes things more complicated).
Here's how you do it: http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.