SaveAs png and specify printing resolution

The problem I’m encountering is that I’m attempting to save copies of scatter plots with millions of data points. Vector formats are a pain to save and re-render as a .png.

The good news is that some more searching found this post (from last year): Canvas scaling when saving

I took a stab at implementing it. It works. I attempted to implement some marker scaling so they are actually visible in the large scale plot… but it does not affect the marker size. I guess I would need to loop through all of the primitives in the canvas and set them that way. In the mean time setting the marker style/size of the scatter plot before running the function works just fine but be prepared for some serious slow down.

void MSaveBigPNG(TString filename="", double scale=5) {
    TCanvas* old_canv = gPad->GetCanvas();

    gROOT->SetBatch(kTRUE);
    gROOT->ForceStyle(kTRUE);

    Int_t orig_msz = gStyle->GetMarkerSize();
    Int_t orig_mst = gStyle->GetMarkerStyle();
    Int_t orig_lt  = gStyle->GetLineWidth();

    gStyle->SetMarkerSize(1.0+scale/5);
    gStyle->SetMarkerStyle(20);
    gStyle->SetLineWidth(orig_lt*scale);

    if(filename = "") {
        filename = old_canv->GetName();
        filename += ".png";
    }

    Int_t old_width  = old_canv->GetWindowWidth();
    Int_t old_height = old_canv->GetWindowHeight();

    Int_t new_width = old_width * scale;
    Int_t new_height= old_height* scale;

    TCanvas* temp_canvas = new TCanvas("temp", "", new_width, new_height);
    old_canv->DrawClonePad();

    temp_canvas->Draw();
    temp_canvas->SaveAs(filename);
    temp_canvas->Close();

    gStyle->SetMarkerSize(orig_msz);
    gStyle->SetMarkerStyle(orig_mst);
    gStyle->SetLineWidth(orig_lt);

    gROOT->ForceStyle(kFALSE);
    gROOT->SetBatch(kFALSE);

    return;
}