SQLite and Images
Hello world
I have a problem with Sqlite and the BLOB data type, and Google was not helpful, because I guess that there is no just enough examples yet...
What I do is the following: I use sqlite to store Images as blobs, as seen here. The table has only two columns, url TEXT and BLOB value
connection.begin(); sql = "INSERT INTO blobs (url, value) VALUES (@a, @b)"; sqlStatement.text = sql; for (var i:int = 0, n:int = images.length; i < n; i++) { sqlStatement.parameters["@a"] = images[i].url; sqlStatement.parameters["@b"] = images[i].data; sqlStatement.execute(); sqlStatement.clearParameters(); } connection.commit();
whereas the images [i] .url are strings, data BitmapData.
Now the question is: How can I get the image of the BitmapData again? What I'm trying to do is the following
public function getBlob(url:String = null):Object { var dp:DataProvider = new DataProvider; try { connection.begin(); var sql:String; if (url) { sql = "SELECT value FROM blobs WHERE url = @a"; sqlStatement.text = sql; sqlStatement.parameters["@a"] = url; } else { sql = "SELECT * FROM blobs"; sqlStatement.text = sql; } sqlStatement.execute(); sqlStatement.clearParameters(); var result:SQLResult = sqlStatement.getResult(); for each (var obj:Object in result.data){ if (obj != null) dp.addItem(obj); } connection.commit(); } catch (e:SQLError) { alert.title = "Database Error (" + e.errorID + ")"; alert.message = "Error: " + e.message + "\n" + e.details; alert.modalAlpha = 0.1; alert.dialogSize = DialogSize.SIZE_SMALL; alert.addButton("OK"); alert.show(IowWindow.getAirWindow().group); connection.rollback(); return null; } return dp; }
and
var dp:DataProvider = getBlob(_newUrl) as DataProvider; trace(dp.data[0].value is BitmapData);
but which always returns false: All that it is said that dp.data [0] .value is an object which I can't access
Any tips?
This seems to work, using built bitmapData as byteArray, getPixels, setPixels.
Thank you
MIke
package { import flash.data.SQLConnection; import flash.data.SQLResult; import flash.data.SQLStatement; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.errors.SQLError; import flash.filesystem.File; import flash.geom.Rectangle; import flash.utils.ByteArray; [SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")] public class SQLBitmapBlob extends Sprite { private var sqlDatabase:File; private var sqlConnection:SQLConnection; private var sqlStatement:SQLStatement; private var sqlResult:SQLResult; private static const BITMAP_WIDTH:int = 96; private static const BITMAP_HEIGHT:int = 96; public function SQLBitmapBlob() { super(); // Init Database sqlDatabase = File.applicationStorageDirectory.resolvePath("dbBlob2.db"); sqlConnection = new SQLConnection(); sqlConnection.open(sqlDatabase); sqlStatement = new SQLStatement(); sqlStatement.sqlConnection = sqlConnection; // Create the table if it doesn't exist sqlStatement.text = "CREATE TABLE IF NOT EXISTS blob (id INTEGER PRIMARY KEY AUTOINCREMENT, picture BLOB)"; try{sqlStatement.execute();} catch (error:SQLError){trace("SQL STATEMENT: " + sqlStatement.text + "\n Error: " + error.details);} // Create a random bitmapData var bmpData:BitmapData = new BitmapData(BITMAP_WIDTH, BITMAP_HEIGHT, true, 0x000000); var bytArray:ByteArray = new ByteArray; bmpData.noise(25); bytArray.writeBytes(bmpData.getPixels(new Rectangle(0,0, BITMAP_WIDTH, BITMAP_HEIGHT))); // Save BitmapData to Database sqlStatement.text = "INSERT INTO blob (picture) VALUES (@picture)"; sqlStatement.clearParameters(); sqlStatement.parameters["@picture"] = bytArray; try {sqlStatement.execute();} catch (error:SQLError){trace("SQL STATEMENT: " + sqlStatement.text + "\n Error: " + error.details);} // Preform Select on Database to return row var loadedBitmapData:BitmapData = new BitmapData(BITMAP_WIDTH, BITMAP_HEIGHT, true, 0x000000); sqlStatement.text = "SELECT * FROM blob WHERE id = last_insert_rowid()"; sqlStatement.clearParameters(); try{sqlStatement.execute();} catch (error:SQLError){trace("SQL STATEMENT: " + sqlStatement.text + "\n Error: " + error.details);} // Convert returned data back to bitmapData var r:Object = new Object(); sqlResult = sqlStatement.getResult(); if (sqlResult.data != null){ r = sqlResult.data[0].picture; loadedBitmapData.setPixels(new Rectangle(0,0, BITMAP_WIDTH, BITMAP_HEIGHT), r as ByteArray); trace("Retrievied record id: " + sqlResult.data[0].id + " from db."); } var bmpDisplay:Bitmap = new Bitmap(loadedBitmapData); addChild(bmpDisplay); } } }
Tags: BlackBerry Developers
Similar Questions
-
Hey there,
So today when I opened Firefox, this is what she looked like. Icons and images are distorted. Text is fine, the scrolling is fine. And this only happens in Firefox (i.e. other programs on my computer, including other browsers are fine).
No idea what it is and how to fix it?
Thank you.
Try disabling graphics hardware acceleration. As this feature has been added to Firefox, it has gradually improved, but there are still some problems.
You will need to restart Firefox before this takes effect so save any work first (e.g. you compose mail, documents online that you are editing, etc.).
Then perform the following steps:
- Click the menu button
then select the Options under Windows or Preferences on Mac or Linux.
- Select the Advanced Panel, then on the general tab.
- Uncheck the use hardware acceleration when available.
- Restart Firefox and see if the problems persist.
This solve your problems? Please report to us!
If the problem is resolved, you should check the updates for your graphics driver by following the steps in these articles in the knowledge base:
Thank you.
- Click the menu button
-
Change your Podcast Description and Image
I've been podcasting for only less than a year. The show has grown and evolved, and I really want to update the description and image to better reflect and explain the show. The current description is super super short. I was told to change the description, I would need to change in the stream. If I do that, it'll ruin everything current subscribers?
What is your show title and / or iTunes store page?
Rob W
-
I've just updated to Firefox Beta 20. Not happy! The options "View Background Image" and "Image Mode" when you right-click is missing. How can I get that back?
These entries should still be there if you right click on an image or an area with a background image.
Start Firefox in Safe Mode to check if one of the extensions (Firefox/tools > Modules > Extensions) or if hardware acceleration is the cause of the problem (switch to the DEFAULT theme: Firefox/tools > Modules > appearance).
- Do NOT click on the reset button on the start safe mode window or make changes.
-
How to save a document to format rich text and images in PDF format manually?
How to save a document to format rich text and images in PDF format manually?
Thank you!
Most applications give the possibility to export or print in PDF format.
What app did you use to create the document?
-
I need to transfer my history of the text and images from my old iPhone to my new iPhone, but have already moved all other data to my new phone via iTunes and spent time to organize. How do I reset this transfer without any? I transfer a 5s to itself.
For your photos, try importing them to your computer and their synchronization then back to the SE.
Import photos and videos from your iPhone, iPad or iPod touch - Apple Support
For your texts, they moved with the backup restore?
-
I have used Firefox for years. I bought a new Dell laptop 3 weeks ago, came with Internet Explorer. Later, I downloaded FF 6.0.1 that I prefer. After a few days of normal use, the Yahoo mail page newspaper came in lower-case letters and images unreadable. I went to the Firefox Options, once again the Options, then content. All fonts have been at least 14. I unchecked the option to leave the web sites chose their own fonts but always get tiny sign in page. When I copy and past the Yahoo mail URL in Internet explorer, the Yahoo login page is normal in size. I uninstalled FF 6.0.1 and downloaded FF 7.0.1 but who gave the same microscopic text. Thanks for any help. Paul
-
Download files and images to iCloud is frozen - Message Finder: 'Download 533581 elements (118,11 GB of 711,95 GB)' but it does not move for days now! Any ideas?
I suspect you might get better results if you uploaded your batch files.
-
Why my image used clipart and images are sent with the document?
Hello Sarahaa1,
Thank you for your message. Which application you use for email? Are you able to you or have you added the Word document as an attachment? Clip art and images remained on the document?Please let us know so that we can better help you get this issue resolved.See you soonEngineer Jason Microsoft Support answers visit our Microsoft answers feedback Forum and let us know what you think.
-
my files and images and electronic messages will not come
Please help me to retrieve my saved files and my photos and my email messages do not come since the change in live my hotmail questions are not resolved I receive no mail and my folderss I saved are all gone and my friends are gone too, I want them back please help me and make stay them behind please
to (perhaps they made me change 3 times not sure) , but is the new thank you elliejutt,
What type of program you use for your email? What has changed before the problem started (did you change of email clients, go online to Live Mail Hotmail, etc...)? Are also the files and images that you mention in the e-mail program do you use?Let us know the details.
Mike - Engineer Support Microsoft Answers
Visit our Microsoft answers feedback Forum and let us know what you think. -
How to: retrieve deleted programs, files and images after reinstalling Vista
Original title: I reinstalled Vista and accidentally deleted programs, files, and photos. Is it possible to recover these? Recovery program does not work.
I had accidentally deleted a program and thought by reinstalling Vista it would bring the program back without changing anything on the computer. By reinstalling, this because all my programs, files and images to be deleted. I tried using the recovery program, and it goes back only to the day that I reinstalled Vista. Is it possible to recover images, lost programs and files?
Buna,
You have loaded Vista again, so you will need to reinstall all your programs once again, sorry for the bad news.
Looking through answers here, you should look to see if you have windows.old folder.
It is information of Support engineers if you have this
Other people here have said they used RECUVA free recovery program file to help find the files when they were in your place
http://www.Piriform.com/Recuva
Revedere.
-
Sound and image's market during video playback by electronic mail.
Original title: videos sent in emails
Sound and image's market during video playback by electronic mail. (IE, trailer attached, you tube)
Hello
1. How do you access the email? Using any email or via an Internet browser client?
2. If you are using Internet explorer, which version is installed on your computer?Method 1.
Given that most online videos require Adobe flash to work I suggest you install Adobe Flash player in Internet Explorer.I recommend you update Adobe flash player from the website below:
http://get.Adobe.com/flashplayer/Method 2.
a. If the problem persists, you can optimize Internet Explorer.
See the link below for more information.
How to optimize Internet Explorer?
http://support.Microsoft.com/kb/936213
b. If nothing works to solve the issue try reset Internet Explorer.
How to reset Internet explorer:
http://support.Microsoft.com/kb/923737Note: After resetting Internet explorer you will need to install Java runtime library and Adobe flash again.WARNING:
Please note that reset the settings of Internet Explorer running resets all of the settings defined by the user, including those established by the installed extensions, toolbars and other add-ons for IE by default. This includes all the security, privacy and settings area. Also this will erase browsing history, delete all temporary Internet, cookies, form data files and especially all the passwords.I hope this helps.Thank you, and in what concerns:
Shekhar S - Microsoft technical support.Visit our Microsoft answers feedback Forum and let us know what you think.
If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly. -
need to activate printing background colors and images, but this is not where it should be in the options/tools/int adv tab. Any ideas?
Try the following. Open IE11, click on the tools, mouse over the option 'Print' option and select "print preview
Select the layout, as shown below.
Place a check in the "case print the background color and images.
Click on the OK"" button.
J W Stuart: http://www.pagestart.com
-
Best approach for the transmission of data and images
We you write an app that will allow the user to take a picture of a document and enter a few bits of information about the document and then send it to our server. It is a mobile extension to a larger system of document management to back office we develop in-house so the intention of this BB app is not not to distribute to the masses.
What is the most practical approach to transmit data and images captured on our server?
-FTP - fooled with it some and a pain
-WebService - did not attempt
-Send an email with the picture attached - seems to work very well
Is there another approach, should I consider?
If you do not already things that communicates to the Server backend, e-mail is probably the easiest way. Crosses all the issues of the segmentation of the image that you would have to do with the Web Service or FTP.
-
Uninstall problem for Adobe photoshop CS and image ready CS.
HI, I'm running windows 7 ultimate problem with the uninstall Adobe Photoshop CS and CS image ready. When I try the uninstall from the Control Panel, it shows that uninstall Adobe Photoshop CS and image ready CS completed successfully. But it has not been uninstalled. After uninstalling, I restart the computer but it always in the programs and features. Please help me.
You have an installation CD that can run the uninstaller for you?
Removal of Windows process «»
Insert the Adobe Photoshop CS2 CD in your computer's CD drive.
1. start the removal process.As with installation, the first window that appears requires you to choose a language for the installer. After you select a language and click OK, the software license agreement appears. Read the software license agreement. If you agree, click on accept. If you click on decline, Setup will stop.
Click on install Photoshop CS2 in the main installation screen, click on next to the Welcome screen.
2 disassembly and repair.When Photoshop CS2 is already installed, you have the option to repair the current version, which solves any problem that may have the version installed, or you can remove the currently installed version. Click on delete and click Next. »
Photoshop help / install/uninstall Photoshop CS2
http://helpx.Adobe.com/Photoshop/KB/install-uninstall-Photoshop-CS2.html
Maybe you are looking for
-
I just installed 15.0.1 and it hangs whenever I open it. Any thoughts?
I upgraded to 15.0.1 and every time I try and open Firefox crashes and send a crash report. I tried to reload several times. I have Windows Vista. Also, I don't find a way to reload an earlier version.Help please.
-
I bought Garageband and want to use it on my laptop and desktop. What do I have to pay twice for Garageband?
-
HP ENVY 17 t-j100 - request help from Windows 7 driver
Hello Make enterprise software that does not work on windows 8, I have to install windows 7. I have found almost all of the missing drivers with relative ease. I'm missing one as follows: PCI Simple Communications controller PCI\VEN_8086 & DEV_8C3A &
-
Default settings of the backlit keyboard
Is it possible to have the backlit keyboard to activate by default? (Acer Aspire M5)
-
My windows update to install a new version of windows update says it acts like it will download and install it then gives me the error code 80070020 and says that my computer is unable to download or install new updates or new version of the windows