mirror of
https://github.com/alexkay/spek.git
synced 2026-12-02 03:45:10 +03:00
Save spectrogram as a PNG image
This commit is contained in:
1 parent
80b2a25f02
commit
f01ec84bec
2 files changed
+33
-6
No files matched your search
@@ -30,7 +30,7 @@ namespace Spek {
|
||||
|
||||
private ImageSurface image;
|
||||
private ImageSurface palette;
|
||||
private const int PADDING = 60;
|
||||
private const int PADDING = 40;
|
||||
private const int GAP = 10;
|
||||
private const int RULER = 10;
|
||||
|
||||
@@ -51,6 +51,12 @@ namespace Spek {
|
||||
start ();
|
||||
}
|
||||
|
||||
public void save (string file_name) {
|
||||
var surface = new ImageSurface (Format.RGB24, allocation.width, allocation.height);
|
||||
draw (new Context (surface));
|
||||
surface.write_to_png (file_name);
|
||||
}
|
||||
|
||||
private void start () {
|
||||
// The number of samples is the number of pixels available for the image.
|
||||
// The number of bands is fixed, FFT results are very different for
|
||||
@@ -84,15 +90,20 @@ namespace Spek {
|
||||
}
|
||||
|
||||
private override bool expose_event (EventExpose event) {
|
||||
double w = allocation.width;
|
||||
double h = allocation.height;
|
||||
|
||||
var cr = cairo_create (this.window);
|
||||
|
||||
// Clip to the exposed area.
|
||||
cr.rectangle (event.area.x, event.area.y, event.area.width, event.area.height);
|
||||
cr.clip ();
|
||||
|
||||
draw (cr);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void draw (Context cr) {
|
||||
double w = allocation.width;
|
||||
double h = allocation.height;
|
||||
|
||||
// Clean the background.
|
||||
cr.set_source_rgb (0, 0, 0);
|
||||
cr.paint ();
|
||||
@@ -119,8 +130,6 @@ namespace Spek {
|
||||
cr.set_source_surface (palette, 0, 0);
|
||||
cr.paint ();
|
||||
cr.identity_matrix ();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void put_pixel (ImageSurface surface, int x, int y, uint32 color) {
|
||||
|
||||
@@ -43,6 +43,13 @@ namespace Spek {
|
||||
open.clicked.connect (on_open_clicked);
|
||||
toolbar.insert (open, -1);
|
||||
|
||||
var save = new ToolButton.from_stock (STOCK_SAVE);
|
||||
save.is_important = true;
|
||||
save.add_accelerator (
|
||||
"clicked", group, 'S', ModifierType.CONTROL_MASK, AccelFlags.VISIBLE);
|
||||
save.clicked.connect (on_save_clicked);
|
||||
toolbar.insert (save, -1);
|
||||
|
||||
toolbar.insert (new SeparatorToolItem (), -1);
|
||||
|
||||
var quit = new ToolButton.from_stock (STOCK_QUIT);
|
||||
@@ -84,6 +91,17 @@ namespace Spek {
|
||||
chooser.destroy ();
|
||||
}
|
||||
|
||||
private void on_save_clicked () {
|
||||
var chooser = new FileChooserDialog (
|
||||
_("Save File"), this, FileChooserAction.SAVE,
|
||||
STOCK_CANCEL, ResponseType.CANCEL,
|
||||
STOCK_SAVE, ResponseType.ACCEPT, null);
|
||||
if (chooser.run () == ResponseType.ACCEPT) {
|
||||
spectrogram.save (chooser.get_filename ());
|
||||
}
|
||||
chooser.destroy ();
|
||||
}
|
||||
|
||||
private void on_about_clicked () {
|
||||
string[] authors = {
|
||||
"Alexander Kojevnikov <alexander@kojevnikov.com>"
|
||||
|
||||
Reference in new issue
Block a user