Hi All
I have a question:
When creating a PictureBox, you can set an image that is in resources (the IMAGE property) or directly from the hard disk (the ImageFromFile property). However, I did not find in the help a way to send a CMemBmp image. That is, an image, created on the fly using drawing functions. Is this possible by standard means, without using hacker tricks?
Hi VANYA,
Maybe Jose will be better able to answer this specific question as WinFBE uses CImageCtx as the underlying control for the "PictureBox". I see that you are also using Jose's CMemBmp class to create the bitmap on the fly.
I wonder if there is an easy, elegant, way to use the hDC from CMemBmp class to feed into the CImageCtx control. The CImageCtx control uses GDI+ for its graphics so maybe it can initialize the required GDI+ pointers using GdipCreateFromHDC using the hDC from CMemBmp?
Jose, what do you think? Would that be do-able?
No, it is not doable. The problem with GDI+ is that it needs to lock the image source, so it has to be a disk file of a resource file.
It can be done using the graphic control (CGraphCtx), which has a DrawBitmap method that accepts a CMemBmp reference.
What you can do is to save the memory bitmap to file with one of the SaveBitmapAsxxx methods and then load it to the image control.
Thanks Jose, appreciate the answer. :-)
Thanks for the answers!
Quote from: José Roca on January 22, 2021, 12:50:25 PM
What you can do is to save the memory bitmap to file with one of the SaveBitmapAsxxx methods and then load it to the image control.
This is extremely ineffective when animating a drawing dynamically.
This means that in the visual editor WinFBE users are deprived of an easy way to create a work surface and draw something on it. I understand correctly?
If this is the case, then this is certainly upsetting, because I was very happy with how easy it is in WinFBE to interact between the created controls.
Everything is done so well that almost all the work is done by WinFBE, all that remains is to add a few lines of event handling code.
Of course, it won't be difficult to create your own drawing surface right in the code (for example, the same Static control).
And draw on it without any problems using GDI or GDI+ (e.g. by timer), as well as send Bitmap GDI there directly using SendMessage (STM_SETIMAGE).
I confess I thought that in WinFBE | WinFBX this is how is implemented, but it looks like some other method is applied there.
For example:
dim shared as HWND winStatic
Function frmMain_Load( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
winStatic = CreateWindowEx(WS_EX_CLIENTEDGE, "static", 0, WS_CHILD Or WS_VISIBLE Or SS_ICON, 10,10,150,150, sender.hWindow , Cast(HMENU,1), 0, 0)
Using GDIPLUS
Dim ULONG_PTR_01 AS ULONG_PTR
DIM GDIPLUSSTARTUPINPUT_01 AS GDIPLUSSTARTUPINPUT
GDIPLUSSTARTUPINPUT_01.GdiplusVersion = 1
IF (GDIPLUSSTARTUP(@ULONG_PTR_01, @GDIPLUSSTARTUPINPUT_01, NULL) <> 0) THEN
PRINT "FAIL"
EndIf
Function = 0
End Function
''
''
Function frmMain_Timer1_Elapsed( ByRef sender As wfxTimer, ByRef e As EventArgs ) As LRESULT
Dim As PVOID GPIMAGE_01 , GpGraphics , GpGraphics2
Dim pen As GpPen Ptr
GdipCreateFromHWND( winStatic ,@GpGraphics2)
GdipCreateBitmapFromScan0(150,150, 0, PixelFormat32bppARGB, NULL, @GPIMAGE_01)
GdipGetImageGraphicsContext(GPIMAGE_01,@GpGraphics)
GdipCreatePen1(&hFF0000FF,3,Unitpixel,@pen)
GdipDrawLine(GpGraphics,pen , 5, 5, 140, 140)
GdipDrawImage(GpGraphics2,GPIMAGE_01,0,0)
GdipDeletePen(pen)
GdipDeleteGraphics(GpGraphics)
GdipDeleteGraphics(GpGraphics2)
GdipDisposeImage(GPIMAGE_01)
Function = 0
End FunctionAlso, GDI and GDI + images can be easily converted to each other using GdipCreateHBITMAPFromBitmap , GdipCreateBitmapFromHBITMAP.
José, Paul , I hope in the future you will supplement the editor with some element for dynamic drawing, and dynamic loading of images directly from memory.
> This means that in the visual editor WinFBE users are deprived of an easy way to create a work surface and draw something on it. I understand correctly?
WinFBX has a graphic control that allows to draw using GDI, GDI+ and even OPENGL.
See: https://github.com/JoseRoca/WinFBX/blob/master/docs/Graphics/CGraphCtx%20Class.md
In the Examples/CGdiPlus folder there are several hundred examples that use GDI+ with the graphic control.
So, I already have done my job.
Quote from: José Roca on January 22, 2021, 05:57:14 PM
In the Examples/CGdiPlus folder there are several hundred examples that use GDI+ with the graphic control.
So, I already have done my job.
Yes, good work.
I realized that while drawing (including images) needs to be completely hand-written in code. Hopefully Paul finds the time and willingness to place the CGraphCtx control among other controls in WinFBE. Thanks again for the answers!
Paul!
There are 2 problems:
1) Not a mistake, rather a request. The Image Manager window is small in width for the Russian interface (the last button is not visible). Is it possible to make this window expandable?
2) It seems to me to be a mistake. I will attach a short video to make it clearer (both problems are shown in it)
Quote from: VANYA on January 23, 2021, 02:25:24 AM
I realized that while drawing (including images) needs to be completely hand-written in code. Hopefully Paul finds the time and willingness to place the CGraphCtx control among other controls in WinFBE. Thanks again for the answers!
Thanks, your request has been added to my to do list.
Thanks for the
Quote from: VANYA on January 23, 2021, 10:05:51 AM
Paul!
There are 2 problems:
1) Not a mistake, rather a request. The Image Manager window is small in width for the Russian interface (the last button is not visible). Is it possible to make this window expandable?
2) It seems to me to be a mistake. I will attach a short video to make it clearer (both problems are shown in it)
Thanks for the reports. I have added these issues to be fixed for next update.
Is it possible to clear a picture box?
Form2.Picture1.ImageFromFile c
If c is an empty string or file c is not found, the previous image is not cleared.
Alternative method (dynamically created image control)
pImageCtx->LoadImageFromFile(c)
If c is an empty string or file c is not found, the previous image is cleared.
That sounds reasonable. :-)
The underlying CImageCtx class has a method called Clear for that purpose.
Quote from: Paul Squires on January 24, 2021, 01:59:59 PM
Thanks for the Quote from: VANYA on January 23, 2021, 10:05:51 AM
Paul!
There are 2 problems:
1) Not a mistake, rather a request. The Image Manager window is small in width for the Russian interface (the last button is not visible). Is it possible to make this window expandable?
2) It seems to me to be a mistake. I will attach a short video to make it clearer (both problems are shown in it)
Thanks for the reports. I have added these issues to be fixed for next update.
Both of these issues are now fixed and will be in Version 2.1.9.
Quote from: Bumblebee on January 27, 2021, 10:38:03 AM
Is it possible to clear a picture box?
Form2.Picture1.ImageFromFile c
If c is an empty string or file c is not found, the previous image is not cleared.
Alternative method (dynamically created image control)
pImageCtx->LoadImageFromFile(c)
If c is an empty string or file c is not found, the previous image is cleared.
An invalid of empty image name will now clear any existing image from the control.