Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » Bazaar » RasterCtrl - Opening image using StringStream
RasterCtrl - Opening image using StringStream [message #55404] Sat, 07 November 2020 15:25
Runik is currently offline  Runik
Messages: 5
Registered: February 2013
Location: France
Promising Member
Hello,

I've been toying around with RasterCtrl to display a huge image stored as a string in a Sqlite database.
Current implementation opens a file using its path through the file selector, but I wanted to be able to open the saved string directly.
So I created a new private function with the shared code named OpenCommon()
bool RasterCtrl::OpenCommon(){
	if(!raster)
		return false;
	
	// loads pages in array of memoryrasters
	pages.Clear();
	for(curPage = 0; curPage < raster->GetPageCount(); curPage++)
	{
		raster->SeekPage(curPage);
		pages.Add().Load(*raster);
	}
	curPage = 0;
	
	// signals that stream is opened
	isOpened = true;
	
	// if multipage, shows thumbnails, otherwise not
	if(raster->GetPageCount() > 1)
		ShowThumbnails(true);
	else
		ShowThumbnails(false);
	
	// signal page changed to thumbs and view
	thumbs->Layout();
	view->Layout();
	
	return true;
} // END RasterCtrl::OpenCommon()


And I overloaded the current Open() function to load the data from the StringStream :
///////////////////////////////////////////////////////////////////////////////////////////////
// opens an image file in control
bool RasterCtrl::Open(String const &fileName)
{
	// if already opened, closes current stream
	if(isOpened)
		Close();
	
	// opens file and associate to raster
	if(!imageStream.Open(fileName))
		return false;
	raster = StreamRaster::OpenAny(imageStream);
	
	return OpenCommon();
	
} // END RasterCtrl::Open()

bool RasterCtrl::Open(StringStream& str)
{
	// if already opened, closes current stream
	if(isOpened)
		Close();
	
	raster = StreamRaster::OpenAny(str);
	
	return OpenCommon();
	
} // END RasterCtrl::Open()


Nothing fancy Very Happy

I'm not sure if there's a better way to do it, but if there is I'm all ears Smile
Previous Topic: AutoScroller package update
Goto Forum:
  


Current Time: Wed Nov 25 08:17:18 CET 2020

Total time taken to generate the page: 0.01374 seconds