SetDIBitsToDevice, StretchDIBits, VB6 - gdi

I used to be good with these things but that was a long time ago!
I have a sample program for a frame grabber working fine, it uses this line (after some other stuff) to display the image in the PictureBox:
SetDIBitsToDevice(Picture1.hdc, 0, 0, gSizeX, gSizeY, 0, 0, 0, gSizeY, gSurfAddr, bmpInfo, DIB_RGB_COLORS)
All I want to do is to change this so I can create a scaled image. So I changed this line to:
StretchDIBits(Picture1.hdc, 0, 0, w, h, 0, 0, gSizeX, gSizeY, gSurfAddr, bmpInfo, DIB_RGB_COLORS, vbSrcCopy)
.. where w and h are the dimension of the image I want (I tried same as gSizeX/y at first, about 700 * 500).
But I get no image, sometimes just white, sometimes what looks like uninitialised memory.
Have I made a simple mistake or do I need to do more?
Thanks

Try to call SetStretchBltMode before StretchDIBits. Sometimes resizing works incorrectly without SetStretchBltMode. Parameters: COLORONCOLOR (fast resizing), HALFTONE (high-quality resizing).
http://msdn.microsoft.com/en-us/library/dd145089(v=vs.85).aspx

Related

Is there a way to replace the same string across multiple anki cards?

I'm a fan of the dark theme but I'm a little bothered by the lack of contrast with the dark blue color in several of my cards.
I have many cards created years ago where I used the blue color to highlight some of the content and it worked well.
But now, with the dark theme, the contrast of the background with the blue is horrible and uncomfortable on the eye.
as I have many cards, I would like to know if there is a way to perform the same replacement on multiple cards?
I managed to change the blue color on the hidden word type cards but I still have a lot of blue words scattered around the deck.
Looking at the source code for the cards, I realized that I needed to replace all occurrences of
color: rgb(0, 0, 255);
for something like
color: rgb(255, 85, 0);
The simplest way I found to replace text on multiple cards was by operating directly on the sqlite database.
The step by step was more or less this:
Download and install sqlite database reader. Like this one.
Locate the folder on is anki's sqlite file. On windows, just go to %APPDATA%\Anki2 and locate the collection.anki2 file inside some subfolder. Instructions for other platforms are here.
Close anki and make a backup copy of collection.anki2 in case something goes wrong.
Open collections.anki2 in the sqlite database reader application and then run the sql commands to perform the text replacements. For example, for color changes described in the question I run the following SQL codes:
UPDATE notes SET flds = replace( flds 'color: rgb(0, 0, 255);', 'color: rgb(255, 85, 0);');
UPDATE notes SET sfld = replace( sfld 'color: rgb(0, 0, 255);', 'color: rgb(255, 85, 0);');
explaining the command references:
notes is the table that holds the texts of all the cards
flds is the column that holds the text on the front of each card is the
sfld column that contains the text on the back of each card

Gdal substract 1 bit raster gives me hard time

I want to use gdal_calc to subtract one file from another. It works, but I get the wrong result all the time no matter what command line i try.
For your understanding I created 3 files.
Picture A:
Picture B:
Picture C:
As you can see I always get the overlap as result but I need the other part.
Desired Result:
gdal_calc.py -A pica.tif -B picb.tif --outfile=result.tif --calc="A-B"
Change the line to
gdal_calc.py -A pica.tif -B picb.tif --outfile=result.tif --calc="B-A"
or swap filenames doesn't work? I always get the same result.
I also delete the output file before trying new stuff so thats not the problem that I always look at the same file.
What are the values of your black and white pixels? Usually white would be 1 (or 255), and black 0, but that's just a guess. If that's the case, you probably want the inverse, so something like (1-A)-(1-B) (if your values are really 1bit).
For testing\debugging, it's a good idea to first convert both input images to an unsigned integer datatype. For example:
gdal_translate -ot Int32 pica.tif pica_int32.tif
That would allow negative values in the result, because gdal_calc does not convert the data to a new "working datatype" (as gdalwarp can do with -wtfor example). So that would mean you're doing the calculation in the input datatype (probably Byte?). See the "Note" box at:
https://gdal.org/programs/gdal_calc.html#cmdoption-type
And if you're subtracting, and the datatype is Byte, it probably causes results beyond the valid range of that datatype (like -1). Normal Numpy behavior is to simply "wrap around" (instead of clip etc), so that might cause some surprising results, for example:
import numpy as np
a = np.array([1, 0, 1, 1], dtype=np.uint8)
b = np.array([0, 1, 254, 255], dtype=np.uint8)
a - b
Results in:
array([ 1, 255, 3, 2], dtype=uint8)

QT 4.8.5 - Popup menu is shown in wrong place - SLED 11

I am developing an applications toolbar in QT 4.8.5 (this version is mandatory for my client) on a SLED 11.
I am also in a multimonitor environment.
My purpose is to show an extended toolbar on a specified monitor and a reduced one on the others.
From the main toolbar is possibile to open different applications installed in the system. These applications can be QT based or not.
In order to make xserver to handle the toolbar as a docking window and reserve the space on the desktop (so the other windows cannot be moved on the toolbar and make the window maximization not cover the toolbar) I used some xlib call.
This is the way I reserved the space:
void ToolbarWindow::dock(int x, int y, int width, int height)
{
#ifdef Q_WS_X11 //only define on Qt 4.X
Display *display = QX11Info::display();
// Change the window type in order to make it DOCK.
Atom tmp = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DOCK", False);
XChangeProperty(display,
winId(),
XInternAtom(display, "_NET_WM_WINDOW_TYPE", False),
XA_ATOM ,
32,
PropModeReplace,
(unsigned char *)&tmp, 1);
// Reserve the space.
// [0]left, [1]right, [2]top, [3]bottom, [4]left_start_y, [5]left_end_y, [6]right_start_y, [7]right_end_y, [8]top_start_x, [9]top_end_x, [10]bottom_start_x, [11]bottom_end_x
long insets[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
insets[2] = height;
insets[8] = x;
insets[9] = x+width;
XChangeProperty(display,
winId(),
XInternAtom(display, "_NET_WM_STRUT", False),
XA_CARDINAL ,
32,
PropModeReplace,
(unsigned char *)&insets, 4);
XChangeProperty(display,
winId(),
XInternAtom(display, "_NET_WM_STRUT_PARTIAL", False),
XA_CARDINAL ,
32,
PropModeReplace,
(unsigned char *)&insets, 12);
#endif
}
Everything seems to work fine, but after some tests I had a big problem with the QT dropdown menu.
It seems that, when QT calculate the position of a dropdown it consider the max reserved height independently of the monitor the window is in.
Here there are two images showing the problem.
The first image show that the problem can be test even in QTCreator dropdown menu.
The second image show a test I made in order to see what happened on combobox dropdown on a custom QMainWindow.
The problem seems to be the same.
I can also add that moving the window beneath the height of the main toolbar on the second monitor the dropdown position is correct.
Moreover other non-QT application DO NOT have this behavior, so I think this is a QT 4.8.5 problem during the dropdown positioning.
I also found similar bugs related to Mac OS X.
I do not know if these bugs can be meaningful but I will list them anyway:
https://bugreports.qt.io/browse/QTBUG-36672
https://bugreports.qt.io/browse/QTBUG-36984
https://bugreports.qt.io/browse/QTCREATORBUG-11364
Anyone can help me found out a solution to this problem?
Thanks a lot.
This Qt bug looks very similar: QMenu size is not shown properly on dual monitor and one with lower resolution.
It includes a patch for Qt (although it may be out of date now) which may correct it.

AutoIT get child window from a parent window

I came across a problem which looks trivial to me but I can't find a valid solution after googling for an hour.
I want to fill in a window security popup window.
This is part of a selenium test, that can run in parallel next to other tests.
So in order to be sure that my autoit script fills in the correct popup (and not form another test that is running), i want to identify this popup as a child of a parent window. Is there an easy way to do this?
The code i had so far:
$browserHandl = WinWait($parentTitle)
WinActivate($browserHandl, "")
$popUpHandl = WinWait("Windows Security")
So my fear is that WinWait will return one of all the open Windows Security popups currently open on the machine.
So:
1. Is there a way to obtain the childwindows of a parent window when i got its handle?
2. Is my fear correct that i indeed will have a race condition with multiple tests running at the same time?
input box open
input box hidden
I used a progress to hide what I needed to.
add #include
$file = GUICtrlCreateInput("", 10, 5, 350, 25)
You need 3 lines for the Marquee
Local $iProgress = GUICtrlCreateProgress(30, 10, 270, 20, $PBS_MARQUEE)
GUICtrlSendMsg($iProgress, $PBM_SETMARQUEE, 1, 50)
and to make it cover the input box
and 0 to stop and remove the Marquee GUICtrlSendMsg($iProgress, $PBM_SETMARQUEE, 0, 50) ; Send the message $PBM_SETMARQUEE and wParam of 0 to stop the scrolling marquee.

.NET Antialias not working on server

I have an ASP.NET web application that display some images. For thumbnail display, I have to resize them. Here is my code:
var newImage = new Bitmap(sourceImage, width, height);
var g = Graphics.FromImage(newImage);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(newImage, 0, 0, newImage.Width, newImage.Height);
newImage.Save(path,GetEncoder(ImageFormat.Jpeg), myEncoderParameters);
Everything looks ok if I run in LOCALHOST. However, when I publish on server, the image quality is very poor and broken.
As Microsoft documentation (http://msdn.microsoft.com/en-us/library/system.drawing.graphics.smoothingmode%28v=vs.110%29.aspx), the System.Drawing namespace is not support for some platform, but seems like that's not my case (I'm not very sure). This is my server system specification: http://i.stack.imgur.com/ByVZ1.jpg (Please follow the link, I do not have enough reputation to post image).
Can anyone please help me with this. Thanks very much.
Add the following to your Graphics settings.
g.CompositingQuality = CompositingQuality.HighQuality;
I'm thinking CompositingQuality.Default may be different between your two machines.
Graphics.CompositingQuality Documentation
I got an answer by myself. The problem is when I call
g.DrawImage(newImage, 0, 0, newImage.Width, newImage.Height);
It will draw an resized image into itself, that is the object:
new Bitmap(sourceImage, width, height));
so all the settings of the graphic object is not affected. The resize functioned actually at the above line of code.
The correct solution should be:
g.DrawImage(sourceImage, 0, 0, newImage.Width, newImage.Height);
And everything works now.

Resources