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 » Community » Newbie corner » SaveFile progress tracking (SaveFile progress tracking with Progress dialog or ProgressIndicator)
icon3.gif  SaveFile progress tracking [message #58282] Fri, 08 April 2022 20:16 Go to next message
Mountacir is currently offline  Mountacir
Messages: 45
Registered: November 2021
Member
Hello,

How to track the progress of SaveFile with Progress dialog or ProgressIndicator?
I have this big image that takes a couple of seconds to save, I couldn't figure out how to show it's progress.
Any help is appreciated. Thanks!


void Test::ImgSave(){
	
	fsn.DefaultExt("png");
	if(!fsn.ExecuteSaveAs()) return;
	String fn = fsn;
	int w = 10000;
	int h = 10000;
	
	work.Run([=] {
		
		ImageDraw dw(w, h);
		dw.DrawRect(0, 0, w, h, White());        
		ImageBuffer img(dw);
		img.SetDPI(Size(300,300));
		PNGEncoder encoder;

		encoder.SaveFile ( fn, img ); //How to track progress of this?
		
		GuiLock __;
		statusbar = "Saved!";
	});
	
}

Re: SaveFile progress tracking [message #58285 is a reply to message #58282] Sat, 09 April 2022 21:53 Go to previous message
Mountacir is currently offline  Mountacir
Messages: 45
Registered: November 2021
Member
I found this solution from RasterEncoder.cpp
Works perfectly!

void Test::ImgSave(){
	
	fsn.DefaultExt("png");
	if(!fsn.ExecuteSaveAs()) return;
	String fn = fsn;
	int w = 10000;
	int h = 10000;
	
	work.Run([=] {
		
		ImageDraw dw(w, h);
		dw.DrawRect(0, 0, w, h, White());        
		ImageBuffer img(dw);
		img.SetDPI(Size(300,300));

		ImageRaster raster(img);
		PNGEncoder encoder;
		FileOut out(fn);
		
		encoder.SetStream(out);
		Size sz = raster.GetSize();
		encoder.SetDots(raster.GetInfo().dots);
		encoder.SetHotSpot(raster.GetInfo().hotspot);
		encoder.Create(sz, raster);

		for(int i = 0; i < sz.cy; i++){
			encoder.WriteLine(raster[i]);
			
			GuiLock __;
			if (i==0){
				progressindicator.Set(0,sz.cy);
				progressindicator.Show();
			}
			progressindicator.Set(i);			
		}
		
		GuiLock __;
		statusbar = "Saved!";
	});
	
}
Previous Topic: Need pointers for USB HID
Next Topic: Customization of TheIDE (PLUGIN)
Goto Forum:
  


Current Time: Fri Mar 29 09:08:21 CET 2024

Total time taken to generate the page: 0.02029 seconds