Contrary to a simple TQuickRep, the TQRCompositeReport component doesn't have the PreviewInitialState property to control the preview size.
Is there any way to preview a composite report maximized?
(the default state is wsNormal)
Use the TQRCompositeReport::OnFinished event:
#include "QuickRpt.hpp"
#include "QRPrev.hpp"
void __fastcall TForm1::QRCompositeReportFinished(TObject *Sender)
{
for(int i(0); i < Screen->FormCount; ++i)
if (Screen->Forms[i]->ClassNameIs("TQRStandardPreview"))
static_cast<TQRStandardPreview *>(Screen->Forms[i])->WindowState = wsMaximized;
}
Related
I'm new to printer
How to print alpha image?
I'm using Gdi+'s DrawImage to draw image.
(Light-gray part is Black Color with 20% alpha)
But, Results it not as I expected.
It seems like discard alpha.
I'm using following code to print
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;
INT main()
{
// Initialize GDI+.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
// Get a device context for the printer.
HDC hdcPrint = CreateDC(NULL, TEXT("\\\\printserver\\HP CP3505_2F"), NULL, NULL);
DOCINFO docInfo;
ZeroMemory(&docInfo, sizeof(docInfo));
docInfo.cbSize = sizeof(docInfo);
docInfo.lpszDocName = L"GdiplusPrint";
Bitmap image(L"e:\\__.png");
StartDoc(hdcPrint, &docInfo);
StartPage(hdcPrint);
Graphics* graphics = new Graphics(hdcPrint);
Pen* pen = new Pen(Color(255, 0, 0, 0));
graphics->DrawImage(&image, 50, 50);
delete pen;
delete graphics;
EndPage(hdcPrint);
EndDoc(hdcPrint);
DeleteDC(hdcPrint);
GdiplusShutdown(gdiplusToken);
return 0;
}
But, Using Word(MS-Office) image is printed as expected.
Please help.
Edit:
GDI Alphablend function draws image alpha part as a gray color.
It looks fine.
But, Overlapping alpha is not working correctly.
It simply just draw a gray alpha part twice.
Not an alpha blend.
source
I want to draw a line using mouse-event in Opencv in a webcam frame. I also want to erase it just like an eraser in MS-Paint.How can i do it? I dont have much idea about it. But i have this scrambled pseduo code from my head which can be completely wrong but i will write it down anyway. I would like to know how to implement it in c++.
So, i will have two three mouse event-
event 1- Mouse leftbuttonup-- this will be used to start the drawing
event 2- Mouse move -- this will be used to move the mouse to draw
event 3:- Mouse leftbuttondown-this will be used to stop the drawing.
event 4- Mouse double click - this event i can use to erase the drawing.
I will also have a drawfunction for a line such as line(Mat image,Point(startx,starty),Point(endx,endy),(0,0,255),1));
Now, i dont know how to implement this in a code format. I tried a lot but i get wrong results. I have a sincere request that please suggest me the code in Mat format not the Iplimage format. Thanks.
please find working code below with inlined explained comments using Mat ;)
Let me know in case of any problem.
PS: In main function, I have changed defauld cam id to 1 for my code, you should keep it suitable for you PC, probably 0. Good Luck.
#include <iostream>
#include <opencv\cv.h>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
class WebCamPaint
{
public:
int cam_id;
std::string win_name;
cv::VideoCapture webCam;
cv::Size frame_size;
cv::Mat cam_frame, drawing_canvas;
cv::Point current_pointer, last_pointer;
cv::Scalar erase_color, paint_color;
int pointer_size;
//! Contructor to initialize basic members to defaults
WebCamPaint()
{
cam_id = 0;
pointer_size = 5;
win_name = std::string("CamView");
current_pointer = last_pointer = cv::Point(0, 0);
erase_color = cv::Scalar(0, 0, 0);
paint_color = cv::Scalar(250, 10, 10);
}
//! init function is required to set some members in case default members needed to change.
bool init()
{
//! Opening cam with specified cam id
webCam.open(cam_id);
//! Check if problem opening video
if (!webCam.isOpened())
{
return false;
}
//! Reading single frame and extracting properties
webCam >> cam_frame;
//! Check if problem reading video
if (cam_frame.empty())
{
return false;
}
frame_size = cam_frame.size();
drawing_canvas = cv::Mat(frame_size, CV_8UC3);
//! Creating Activity / Interface window
cv::namedWindow(win_name);
cv::imshow(win_name, cam_frame);
//! Resetting drawing canvas
drawing_canvas = erase_color;
//! initialization went successful ;)
return true;
}
//! This function deals wih all processing, drawing and displaying ie main UI to user
void startAcivity()
{
//! Keep doing until user presses "Esc" from Keyboard, wait for 20ms for user input
for (char user_input = cv::waitKey(20); user_input != 27; user_input = cv::waitKey(20))
{
webCam >> cam_frame; //Read a frame from webcam
cam_frame |= drawing_canvas; //Merge with actual drawing canvas or drawing pad, try different operation to merge incase you want different effect or solid effect
cv::imshow(win_name, cam_frame); //Display the image to user
//! Change size of pointer using keyboard + / -, don't they sound fun ;)
if (user_input == '+' && pointer_size < 25)
{
pointer_size++;
}
else if (user_input == '-' && pointer_size > 1)
{
pointer_size--;
}
}
}
//! Our function that should be registered in main to opencv Mouse Event Callback
static void onMouseCallback(int event, int x, int y, int flags, void* userdata)
{
/* NOTE: As it will be registered as mouse callback function, so this function will be called if anything happens with mouse
* event : mouse button event
* x, y : position of mouse-pointer relative to the window
* flags : current status of mouse button ie if left / right / middle button is down
* userdata: pointer o any data that can be supplied at time of setting callback,
* we are using here to tell this static function about the this / object pointer at which it should operate
*/
WebCamPaint *object = (WebCamPaint*)userdata;
object->last_pointer = object->current_pointer;
object->current_pointer = cv::Point(x, y);
//! Drawing a line on drawing canvas if left button is down
if (event == 1 || flags == 1)
{
cv::line(object->drawing_canvas, object->last_pointer, object->current_pointer, object->paint_color, object->pointer_size);
}
//! Drawing a line on drawing canvas if right button is down
if (event == 2 || flags == 2)
{
cv::line(object->drawing_canvas, object->last_pointer, object->current_pointer, object->erase_color, object->pointer_size);
}
}
};
int main(int argc, char *argv[])
{
WebCamPaint myCam;
myCam.cam_id = 1;
myCam.init();
cv::setMouseCallback(myCam.win_name, WebCamPaint::onMouseCallback, &myCam);
myCam.startAcivity();
return 0;
}
I have an OpenCV application that displays a fullscreen window, via:
cv::namedWindow("myWindow", CV_WINDOW_NORMAL)
cv::setWindowProperties("myWindow", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN)
It works fine, but when I have multiple monitors it always displays the fullscreen window on the First monitor. Is there any way to display on the 2nd monitor? I've tried setting X/Y and Width/Height, but they seem to be ignored once fullscreen is enabled.
Edits:
Sometimes pure OpenCV code cannot do a fullscreen window on a dual display. Here is a Qt way of doing it:
#include <QApplication>
#include <QDesktopWidget>
#include <QLabel>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDesktopWidget dw;
QLabel myLabel;
// define dimension of the second display
int width_second = 2560;
int height_second = 1440;
// define OpenCV Mat
Mat img = Mat(Size(width_second, height_second), CV_8UC1);
// move the widget to the second display
QRect screenres = QApplication::desktop()->screenGeometry(1);
myLabel.move(QPoint(screenres.x(), screenres.y()));
// set full screen
myLabel.showFullScreen();
// set Qimg
QImage Qimg((unsigned char*)img.data, img.cols, img.rows, QImage::Format_Indexed8);
// set Qlabel
myLabel.setPixmap(QPixmap::fromImage(Qimg));
// show the image via Qt
myLabel.show();
return app.exec();
}
Don't forget to configure the .pro file as:
TEMPLATE = app
QT += widgets
TARGET = main
LIBS += -L/usr/local/lib -lopencv_core -lopencv_highgui
# Input
SOURCES += main.cpp
And in terminal compile your code as:
qmake
make
Original:
It is possible.
Here is a working demo code, to show a full-screen image on a second display. Hinted from How to display different windows in different monitors with OpenCV:
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main ( int argc, char **argv )
{
// define dimension of the main display
int width_first = 1920;
int height_first = 1200;
// define dimension of the second display
int width_second = 2560;
int height_second = 1440;
// move the window to the second display
// (assuming the two displays are top aligned)
namedWindow("My Window", CV_WINDOW_NORMAL);
moveWindow("My Window", width_first, height_first);
setWindowProperty("My Window", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
// create target image
Mat img = Mat(Size(width_second, height_second), CV_8UC1);
// show the image
imshow("My Window", img);
waitKey(0);
return 0;
}
I've tried different ways to make it working, but unfortunetely it seems that this is not possible using OpenCV. The only thing you can do is probably display one window on main(primary) screen just using your current code and handle second window manually - set window position, resize image, and just use imshow function to display it. Here is some example:
void showWindowAlmostFullscreen(cv::Mat img, std::string windowTitle, cv::Size screenSize, cv::Point screenZeroPoint)
{
screenSize -= cv::Size(100, 100); //leave some place for window title bar etc
double xScallingFactor = (float)screenSize.width / (float)img.size().width;
double yScallingFactor = (float)screenSize.height / (float)img.size().height;
double minFactor = std::min(xScallingFactor, yScallingFactor);
cv::Mat temp;
cv::resize(img, temp, cv::Size(), minFactor, minFactor);
cv::moveWindow(windowTitle, screenZeroPoint.x, screenZeroPoint.y);
cv::imshow(windowTitle, temp);
}
int _tmain(int argc, _TCHAR* argv[])
{
cv::Mat img1 = cv::imread("D:\\temp\\test.png");
cv::Mat img2;
cv::bitwise_not(img1, img2);
cv::namedWindow("img1", CV_WINDOW_AUTOSIZE);
cv::setWindowProperty("img1", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
cv::namedWindow("img2");
while(cv::waitKey(1) != 'q')
{
cv::imshow("img1", img1);
cv::setWindowProperty("img1", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
showWindowAlmostFullscreen(img2, "img2", cv::Size(1366, 768), cv::Point(260, 1080));
}
}
and the result:
Screen size and screen zero point (i don't know whether this is a correct name of this point - generally it's just a point in which there is screen (0,0) point) you can get using some other library or from windows control panel. Screen zero point will display when you will start moving screen:
If you use QT for writing your code, you can possibly utilize QT5's "Widget".
Here is a tutorial that will show you how to display an OpenCV image in a QT Widget.
Once you have that working you can then use something like this:
QScreen *screen = QGuiApplication::screens()[1]; // specify which screen to use
SecondDisplay secondDisplay = new SecondDisplay(); // your widget
** Add your code to display opencv image in widget here **
secondDisplay->move(screen->geometry().x(), screen->geometry().y());
secondDisplay->resize(screen->geometry().width(), screen->geometry().height());
secondDisplay->showFullScreen();
(Code found here on another SO answer)
I have not tried this myself, so I can't guarantee it will work, however, but it seems likely (if not a little overkill)
Hope this helps.
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
int main()
{
cv::Mat im =cv::imread("C:/OpenCV2.3/opencv/samples/cpp/matching_to_many_images/query.png");
if(im.empty())
{
return -1;
}
cv::namedWindow("image", CV_WINDOW_AUTOSIZE);
cv::imshow("image" , im);
cv::waitKey();
return 0;
}
After executing this code sample , i have gray window. Whean i move a cursor on the window, it shows , that something is loading. What's the problem? I'am sure that the imagepath is correct.
I had the same error. Turned out my system missed the msvcp100d.dll and msvcr100d.dll files.
I want to draw text to a DirectX game, so I've injected a DLL which hooks EndPaint. My logic was that since EndPaint is supposed to be the last step in the WM_PAINT operation, I could, in my hook, draw the text, and then call EndPaint myself. By doing this, I avoid the DX interface altogether.
The problem is that it is doing absolutely nothing. Here is my code.
#include <windows.h>
#include "Hooks.h"
static const TCHAR g_cszMessage[] = TEXT("utterly fantastic");
BOOL (WINAPI * _EndPaint)(__in HWND hWnd, __in const LPPAINTSTRUCT lpPaint) = EndPaint;
BOOL WINAPI EndPaintHook(__in HWND hWnd, __in const LPPAINTSTRUCT lpPaint)
{
// write message
TextOut(lpPaint->hdc, 0, 0, g_cszMessage, lstrlen(g_cszMessage));
GdiFlush();
// return original
return _EndPaint(hWnd, lpPaint);
}
BOOL APIENTRY DllMain(__in HINSTANCE hModule, __in DWORD fdwReason, __in __reserved LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(lpvReserved);
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
if (AttachHook(reinterpret_cast<PVOID*>(&_EndPaint), EndPaintHook))
{
DisableThreadLibraryCalls(hModule);
break;
}
return FALSE;
case DLL_PROCESS_DETACH:
DetachHook(reinterpret_cast<PVOID*>(&_EndPaint), EndPaintHook);
break;
}
return TRUE;
}
I know the issue isn't with my AttachHook/DetachHook functions because I've tested via message boxes and confirmed that the hooks are installed. The text simply isn't showing up.
Anyone have any idea? I don't really want to hook the DX interface. Shouldn't it work either way, since WM_PAINT is still used at the base level?
Thanks in advance.
You are better off hooking the present of DirectX and then using ID3DXFont to do some font rendering. AFAIK WM_PAINT is not used for DirectX rendering.