PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: PictureBox load image  (Read 669 times)

VANYA

  • Little Newbie
  • *
  • Posts: 13
PictureBox load image
« on: January 22, 2021, 08:05:15 AM »

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?
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9386
  • Windows 10
    • PlanetSquires Software
Re: PictureBox load image
« Reply #1 on: January 22, 2021, 11:32:47 AM »

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?
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Josť Roca

  • Guru Member
  • *****
  • Posts: 3325
Re: PictureBox load image
« Reply #2 on: January 22, 2021, 12:20:25 PM »

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.
« Last Edit: January 22, 2021, 12:32:20 PM by Josť Roca »
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9386
  • Windows 10
    • PlanetSquires Software
Re: PictureBox load image
« Reply #3 on: January 22, 2021, 02:11:03 PM »

Thanks Jose, appreciate the answer. :-)
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

VANYA

  • Little Newbie
  • *
  • Posts: 13
Re: PictureBox load image
« Reply #4 on: January 22, 2021, 04:05:39 PM »

Thanks for the answers!

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:

Code: [Select]
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 Function

Also, 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.

Logged

Josť Roca

  • Guru Member
  • *****
  • Posts: 3325
Re: PictureBox load image
« Reply #5 on: January 22, 2021, 05:27:14 PM »

> 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.

VANYA

  • Little Newbie
  • *
  • Posts: 13
Re: PictureBox load image
« Reply #6 on: January 23, 2021, 01:55:24 AM »


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!
Logged

VANYA

  • Little Newbie
  • *
  • Posts: 13
Re: PictureBox load image
« Reply #7 on: January 23, 2021, 09:35: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)
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9386
  • Windows 10
    • PlanetSquires Software
Re: PictureBox load image
« Reply #8 on: January 24, 2021, 01:27:40 PM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9386
  • Windows 10
    • PlanetSquires Software
Re: PictureBox load image
« Reply #9 on: January 24, 2021, 01:29:59 PM »

Thanks for the
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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Bumblebee

  • Junior Member
  • **
  • Posts: 75
Re: PictureBox load image
« Reply #10 on: January 27, 2021, 10:08: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.
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9386
  • Windows 10
    • PlanetSquires Software
Re: PictureBox load image
« Reply #11 on: January 27, 2021, 11:31:17 AM »

That sounds reasonable. :-)
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Josť Roca

  • Guru Member
  • *****
  • Posts: 3325
Re: PictureBox load image
« Reply #12 on: January 27, 2021, 12:33:36 PM »

The underlying CImageCtx class has a method called Clear for that purpose.

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9386
  • Windows 10
    • PlanetSquires Software
Re: PictureBox load image
« Reply #13 on: March 20, 2021, 06:38:25 PM »

Thanks for the
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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9386
  • Windows 10
    • PlanetSquires Software
Re: PictureBox load image
« Reply #14 on: March 20, 2021, 06:47:41 PM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer