PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Anonymous on September 04, 2005, 03:37:08 PM

Title: Writing to an image
Post by: Anonymous on September 04, 2005, 03:37:08 PM
Hi, my latest project requires me to directly write to a picture control, writing pixels directly, although speed is not as much a concern.
As far as i see it, their are three ways to achieve this...
1) Use a third party DLL and suffer the pains of trying to implement it into a firefly app.
2) Write directly to the file and refresh the image on screen everytime i make a change
3) locate the image in memory and write to memory
The third scheme is far more appealing to me, though i have limited knowledge how to achieve it. I do have limited knowledge of the format of a BMP image. Would you have any suggestions?
note: i only require to write to bits, NOT to draw lines or fill areas.
Title: Writing to an image
Post by: TechSupport on September 05, 2005, 11:34:25 AM
Sorry, but I am not much help when it comes to this sort of thing. :( I have never had the need to deal directly with bitmaps at the bit/byte level.
Title: Writing to an image
Post by: Anonymous on September 05, 2005, 12:00:26 PM
Ok, i kind of thought this might be going a little too far. However, would you be able to tell me if (when i open a picture in a picture control) the picture resides in memory somewhere aswell as on the control?
Title: Writing to an image
Post by: TechSupport on September 05, 2005, 01:35:46 PM
Quote from: twilighte1... the picture resides in memory somewhere aswell as on the control?
If you look at the generated source code for the project you will see that the images are put into standard Windows STATIC controls (using an %STM_SETIMAGE message).

To retrieve the handle of the image you can use the following code:

   Local hImg As Dword
   
   hImg = SendMessage( HWND_FORM1_PICTURE1, %STM_GETIMAGE, %IMAGE_BITMAP, 0)
   
   MsgBox "Bitmap handle is:" & Str$(hImg)
Title: Writing to an image
Post by: Anonymous on September 05, 2005, 07:42:38 PM
Ok, that's cool. How do i set a new image (BMP Picture) into a picture control (at runtime) in the code?
Title: Writing to an image
Post by: TechSupport on September 05, 2005, 08:28:35 PM

   Local FF_zTempString As Asciiz * %MAX_PATH
   Local FF_RECT        As Rect  
   Local FF_hPicture    As Long

   FF_zTempString = "IMAGE_NAME"  '<--- you need to set this
   GetClientRect hWndControl, FF_RECT
   FF_hPicture = LoadImage(App.hInstance, FF_zTempString, %IMAGE_BITMAP, FF_RECT.nRight, FF_RECT.nBottom, %LR_SHARED)
   FF_hPicture = SendMessage( hWndControl, %STM_SETIMAGE, %IMAGE_BITMAP, FF_hPicture)
  'if an old image exists then delete it to avoid resource leak.
  If FF_hPicture Then DeleteObject FF_hPicture


You would need to define the "IMAGE_NAME" to whatever you wish to call the image. The image would reside in a resource file. If you want to load the image from a disk file then you would beed to modify the LoadImage function call to include the %LR_LOADFROMFILE flag:

   FF_zTempString = "mybitmap.bmp"
   GetClientRect hWndControl, FF_RECT
   FF_hPicture = LoadImage(App.hInstance, FF_zTempString, %IMAGE_BITMAP, FF_RECT.nRight, FF_RECT.nBottom, %LR_SHARED or %LR_LOADFROMFILE)
   FF_hPicture = SendMessage( hWndControl, %STM_SETIMAGE, %IMAGE_BITMAP, FF_hPicture)
  'if an old image exists then delete it to avoid resource leak.
  If FF_hPicture Then DeleteObject FF_hPicture


EDIT: Make sure to change the "hwndControl" to the hwnd of the picture control (e.g. HWND_FORM1_PICTURE1).
Title: Writing to an image
Post by: Anonymous on September 06, 2005, 04:34:01 PM
Ok, thanks. It now works