Hi, i have created drawing using paint and i saved it as a image and insert it in database and then placed as a image in paint image but it gives folloawing error when i set image in a paintview
CGContextSaveGState: invalid context 0x0
I have used following code to setimage in paintview
var paintView = Titanium.Painter.createPaintView({
top: 0,
left: 0,
right: 0,
bottom: 0,
strokeColor: '#0f0',
//strokeColor: '#ffffff',
strokeAlpha: 255,
strokeWidth: 10,
});
paintView.addEventListener('touchend',function(e) {
var paintimage = paintView.toImage();
imagedb.addtempImage(paintimage);
});
exports.addtempImage = function(imageitem) {
var db = Ti.Database.open('db');
db.execute('INSERT INTO Tempdrawingimage (tempimage) values (?)', imageitem);
var dbrows =db.execute('SELECT tempimage FROM Tempdrawingimage');
Ti.API.info( dbrows.getRowCount());
dbrows.close();
db.close();
};
sliderbar.addEventListener('swipe',function(e)
{
var tempimg = imagedb.gettempImage(Ti.App.myglobaltempimage);
paintView.clear();
paintView.image = tempimg;
}
});
2 Answers
Accepted Answer
I think the best solution is to actually save the image to the filesystem. Here are a couple of functions I've created that do just that:
var getPaintImage = function(){ var filename = "savedPainting.jpg"; var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,filename); if(!file.exists()){ return 'File not found.'; } else { return Titanium.Filesystem.applicationDataDirectory+filename; } }, var savePaintImage = function(imageBlob){ var filename = "savedPainting.jpg"; var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,filename); file.write(cover); }So, then, you would do the following to save the image:
var savedPainting = paintView.toImage(); savePaintImage(savedPainting);You could, of course, add a parameter to the save and retrieve functions allowing you to use a custom filename as well.
Hope that helps!
you cannot save that image to the database... unless you convert it to a string representation
Your Answer
Think you can help? Login to answer this question!