读取MBTiles数据库里的图片

MBTiles其实就是sqlite3的数据库,是给移动平台离线存储用的

// SqliteTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "CppSQLite3.h"

CppSQLite3DB db;
char* pstrFileName = "P:\\OruxMapsImages.db";

int main()
{
	try
	{
		db.open(pstrFileName);
		unsigned char* bin;
		CppSQLite3Binary  blob;

		FILE* phFilef = fopen("P:\\tile1.jpg", "wb");//注意,图片必须用wb,如果不是二进制,图片保存将不正常

		CppSQLite3Query q;
		q = db.execQuery("select image from tiles;");
 
		if (!q.eof())
		{
			int len = 0;
			const unsigned char* ptr = q.getBlobField("image", len);
			blob.setBinary(ptr, len);// setEncoded((unsigned char*)q.fieldValue("image"));
		}
		printf("file size:%d\n", blob.getBinaryLength());
		const unsigned char* pbin = blob.getBinary();

		unsigned int dwWrite = 0;
		fwrite(pbin, sizeof(unsigned char), blob.getBinaryLength(), phFilef);

		fclose(phFilef);

	}
	catch (CppSQLite3Exception &e)
	{
		printf(e.errorMessage());
	}

    return 0;
}




你可能感兴趣的:(读取MBTiles数据库里的图片)