【问题标题】:FLTK Desktop Screenshot IssueFLTK 桌面截图问题
【发布时间】:2017-10-06 00:33:56
【问题描述】:

我想在 windows 和 linux 上截取我的桌面。

我在 windows(ok) 和 linux 上尝试了这段代码。唯一的问题是,linux 上的深灰色背景(Fl_Box 的屏幕截图文本显示正确)。

下面是代码:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
#include <png.h>

int save_png(const char *file,unsigned char* p,int w,int h){
    FILE *fp;
    fp = fl_fopen(file, "wb");
    if (fp == NULL)return 1;
    png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
                                      0, 0, 0);
    if (png == NULL){
       fclose (fp);
       return 2;
    }
    png_infop info = png_create_info_struct(png);
    png_bytep ptr = (png_bytep)p;
    png_init_io(png, fp);
    png_set_IHDR(png, info, w, h, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
         PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
    png_write_info(png, info);
    for (int i = h; i>0; i--, ptr += w * 3) {
       png_write_row(png,ptr);
    }
    png_write_end(png,info);
    png_destroy_write_struct(&png, &info);
    fclose(fp);
    return 0;
}

class WIN : public Fl_Window {
   public:
   WIN(int w, int h, const char*l = 0):Fl_Window(w,h,l){}

   void draw(){
      Fl_Window::draw();
      uchar *p = fl_read_image(0,0,0,w(),h());
      if(p){
         save_png("test.png",p,w(),h());
         delete[]p;
      }
      hide();
   }
};

int main(){
   WIN *win = new WIN(Fl::w(),Fl::h());
   win->box(FL_NO_BOX);
   Fl_Box b(0,0,win->w(),win->h(),"screenshot");
   b.box(FL_NO_BOX);
   b.labelcolor(FL_RED);
   win->fullscreen();
   win->border(0); //added
   win->show();
   return Fl::run();
}

也许你可以帮我解决这个问题。

【问题讨论】:

    标签: c++ linux windows screenshot fltk


    【解决方案1】:

    通过添加“win->border(0)”找到了解决方案,我将编辑第一篇文章。

    【讨论】:

    • 您可以回答自己的问题。只需将此标记为答案
    • 谢谢,没想到。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多