Giter Club home page Giter Club logo

snipper-snippingtool-lib-windows's Introduction

(works on windows only)

image

Usage:

Creating a new thread when using is advised because destructor of Snipper calls DestroyWindow() which may send WM_QUIT message to your application.

// Creates a hidden popup window, sets global variables etc.
Snipper snipper; 

// Pointer that'll point to pixel array
const RGBQUAD* snipPixels; 

/* Takes the screenshot of window after 2 seconds and paints it in window, makes the user take a snipshot
and returns the array of snipshot's pixels.
snipshot's width and height are accessible via snipper.width and snipper.height
NOTE: If user presses ESC key instead of taking a snipshot, return values is NULL*/

snipPixels=snipper.TakeASnip(2000);

// you can call snipper.TakeASnip() repetitively without having to reset anything.

exampleMain.cpp

#include "src\snipper.hpp"
#include <iostream>
#include <fstream>
#include <vector>
#include <thread>

void foo(){
  
  Snipper snipper;

  const RGBQUAD* snipPixels;

  snipPixels=snipper.TakeASnip(2000);


  /* Write the rgb pixel array to the file*/
  vector<unsigned char> pixels;
  ofstream stream("testData",ofstream::binary);
  
  for(int i=0;i<snipper.height;i++){
    for(int j=0;j<snipper.width;j++){
      pixels.push_back(snipPixels[snipper.width*i+j].rgbRed);
      pixels.push_back(snipPixels[snipper.width*i+j].rgbGreen);
      pixels.push_back(snipPixels[snipper.width*i+j].rgbBlue);
    }
  }

  stream.write((char*)pixels.data(),pixels.size());
  stream.close();
}

int main(){

  // hiding the console window (not necessary)
  ShowWindow(GetConsoleWindow(), SW_HIDE);

  thread myThread(foo);
  myThread.join();
  
  return 0;
}

Compiling:

g++ -o snipper.exe exampleMain.cpp build\snipper.o build\snipperManifest.res -lgdi32

snipper-snippingtool-lib-windows's People

Contributors

zekicaneksi avatar

Stargazers

Oğuzhan Yılmaz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.