U++ framework - RDF feed
type: channel
description: Do not panic. Ask here before giving up.
items: RasterCtrl - Opening image using StringStream

RasterCtrl - Opening image using StringStream
type: item
description: 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 I'm not sure if there's a better way to do it, but if there is I'm all ears
creator: Runik
date: 2020-11-07T14:25:34-00:00