-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from pinebit/image_to_skype_win
clipboard image is not pasted in 'Skype' (win)
- Loading branch information
Showing
13 changed files
with
165 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "clipboard.h" | ||
|
||
#include <QApplication> | ||
#include <QClipboard> | ||
|
||
void copyToClipboard(const QImage& image){ | ||
QApplication::clipboard()->setImage(image); | ||
} | ||
|
||
bool tryPasteFromClipboard(QImage& image) { | ||
image = QApplication::clipboard()->image(); | ||
return (!image.isNull()) ? true : false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
#include <QImage> | ||
|
||
void copyToClipboard(const QImage& image); | ||
bool tryPasteFromClipboard(QImage& image); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CONFIG += static staticlib c++11 | ||
|
||
INCLUDEPATH += $$PWD | ||
|
||
HEADERS += \ | ||
$$PWD/clipboard.h | ||
|
||
SOURCES += \ | ||
$$PWD/clipboard.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#ifdef Q_OS_WIN | ||
#include <platform/windows/clipboard.h> | ||
#else | ||
#include <platform/generic/clipboard.h> | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
win32 { | ||
include(windows/windows.pri) | ||
} | ||
unix:!macx { | ||
include(generic/generic.pri) | ||
} | ||
macx { | ||
include(generic/generic.pri) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "clipboard.h" | ||
#include "image.h" | ||
|
||
#include <QApplication> | ||
#include <QClipboard> | ||
|
||
void copyToClipboard(const QImage& image){ | ||
HBITMAP bitmap = image::convertQImageToHBITMAP(image); | ||
if(bitmap) { | ||
if (::OpenClipboard(NULL)){ | ||
::EmptyClipboard(); | ||
::SetClipboardData(CF_BITMAP, bitmap); | ||
::CloseClipboard(); | ||
} | ||
DeleteObject(bitmap); | ||
} | ||
} | ||
|
||
bool tryPasteFromClipboard(QImage& image) { | ||
image = QApplication::clipboard()->image(); | ||
return (!image.isNull()) ? true : false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
#include <QImage> | ||
|
||
void copyToClipboard(const QImage& image); | ||
bool tryPasteFromClipboard(QImage& image); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
#include "image.h" | ||
|
||
HBITMAP image::convertQImageToHBITMAP(const QImage& image){ | ||
if (image.isNull()) | ||
return 0; | ||
|
||
HDC displayDC = ::GetDC(NULL); | ||
HDC memoryDC = ::CreateCompatibleDC(NULL); | ||
if (!displayDC || !memoryDC){ | ||
return 0; | ||
} | ||
// it is a memory memoryDC that must have a handle selected into it | ||
HBITMAP dummyBitmap = ::CreateCompatibleBitmap(displayDC, image.width(), image.height()); | ||
::ReleaseDC(NULL, displayDC); | ||
HBITMAP oldBitmap = (HBITMAP) ::SelectObject(memoryDC, dummyBitmap); | ||
|
||
BITMAPINFO info; | ||
::memset(&info, 0, sizeof(info)); | ||
info.bmiHeader.biBitCount = image.depth(); | ||
info.bmiHeader.biClrImportant = 0; | ||
info.bmiHeader.biClrUsed = 0; | ||
info.bmiHeader.biCompression = BI_RGB; | ||
info.bmiHeader.biHeight = -image.height(); | ||
info.bmiHeader.biWidth = image.width(); | ||
info.bmiHeader.biPlanes = 1; | ||
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | ||
info.bmiHeader.biSizeImage = image.width() * image.height() * 4; | ||
|
||
HBITMAP bitmap = ::CreateDIBitmap(memoryDC, &info.bmiHeader, CBM_INIT, image.constBits(),(LPBITMAPINFO) &info, DIB_RGB_COLORS); | ||
if (bitmap) { | ||
::SelectObject(memoryDC, oldBitmap); | ||
::DeleteObject(dummyBitmap); | ||
::DeleteDC(memoryDC); | ||
} | ||
return bitmap; | ||
} | ||
|
||
HBITMAP image::captureQWidget(const QWidget& widget){ | ||
HWND hWnd = (HWND)widget.winId(); | ||
HDC displayDC = ::GetDC(hWnd); | ||
if (!displayDC){ | ||
return 0; | ||
} | ||
RECT rectWindow; | ||
::GetWindowRect(hWnd, &rectWindow); | ||
|
||
HDC memoryDC = ::CreateCompatibleDC(displayDC); | ||
HBITMAP bitmap = ::CreateCompatibleBitmap(displayDC, rectWindow.right - rectWindow.left, rectWindow.bottom - rectWindow.top); | ||
if (bitmap) { | ||
::SelectObject(memoryDC, bitmap); | ||
::BitBlt(memoryDC, 0, 0, rectWindow.right - rectWindow.left, rectWindow.bottom - rectWindow.top, displayDC, rectWindow.left, rectWindow.top, SRCCOPY); | ||
} | ||
::ReleaseDC(hWnd, memoryDC); | ||
return bitmap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <QImage> | ||
#include <QWidget> | ||
|
||
#include <windows.h> | ||
#include <wingdi.h> | ||
|
||
class image | ||
{ | ||
public: | ||
static HBITMAP convertQImageToHBITMAP(const QImage& image); | ||
static HBITMAP captureQWidget(const QWidget& widget); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CONFIG += static staticlib c++11 | ||
LIBS += -luser32 | ||
|
||
INCLUDEPATH += $$PWD | ||
|
||
HEADERS += \ | ||
$$PWD/image.h \ | ||
$$PWD/clipboard.h | ||
|
||
SOURCES += \ | ||
$$PWD/image.cpp \ | ||
$$PWD/clipboard.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters