Page 1 of 1

How to show images ?

Posted: Sun Feb 20, 2005 9:27 am
by Mowen
Hi all,

I use PB 3.92 for Linux and I try to show images in a window. But nothing appears. I tried with DrawImage (apparently supported now) and also with an ImageGadget but both methods not work. How can we do :?: It works fine on the Windows version.

Posted: Sun Feb 20, 2005 12:55 pm
by olejr
I had some problems with images too...
Had the desktop set to 16bit,
changed to 24 or 32 bit and it worked...

But this was with v3.91.. Don't know if that's changed..

Posted: Sun Feb 20, 2005 2:59 pm
by Fred
Could you post a little snippet ?

Posted: Sun Feb 20, 2005 4:11 pm
by olejr
@Fred: sure.. :wink:

Code: Select all

LoadImage(1,"logo.bmp") ; renamed PB logo

OpenWindow(0,0,0,200,187,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Linux Image Gadget")
  CreateGadgetList(WindowID())
  ImageGadget(0,0,0,200,187,UseImage(1))

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
When you try to run it on desktop < 24bit.. It gives:
Gdk-ERROR ** : BadMatch (invalid parameter attributes) serial 52 error_code 8 request_code 147 minor_code 3
Gdk-ERROR ** : BadMatch (invalid parameter attributes) serial 53 error_code 8 request_code 147 minor_code 3

And the first time i came over this, i did report it in the bug section.. :wink:
viewtopic.php?t=11727&highlight=

Posted: Sun Feb 20, 2005 8:11 pm
by Mowen
I give another sample with jpeg and SetGadgetState. I am in 24bits color too and I do not get any error messages. Just a blank window without image.

Code: Select all

Enumeration
  #frmMain
  #imgMain
EndEnumeration

UseJPEGImageDecoder()

OpenWindow(#frmMain, 50, 50, 500, 450, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered, "ImageViewer")
CreateGadgetList(WindowID(#frmMain))
ImageGadget(#imgMain, 0, 0, 500, 450, 0)
If LoadImage(1, "test.jpg")
  SetGadgetState(#imgMain, UseImage(1))
Else
  MessageRequester("Error", "Cannot load the image !")
EndIf

Repeat
  EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
End

Posted: Sat Feb 26, 2005 6:59 pm
by Mowen
Any news about this, Fred ? We know you are working on the Windows version for now but can we expect to be solved soon if it is not a major bug ? It is blocking issue on the project I am working on. :(

Posted: Sat Feb 26, 2005 8:17 pm
by Fred
Yes, I will take a look to it quickly.

Posted: Sat Feb 26, 2005 8:38 pm
by Fred
In fact it's because the imagegadget() is created with a null ImageID. If you pass the imageID directly, it should work (little workaround until it's fixed).

Posted: Sat Feb 26, 2005 8:48 pm
by Mowen
Thanks Fred to take a look at it.

In fact I have the same issue when directly using the ImageId as shown in the olejr's code sample.

Posted: Sat Mar 05, 2005 12:03 am
by Mowen
Hi Fred,

I tried the new libraries (Image and Gadget) available in beta/linux. The direct image allocation in the ImageGadget() function works now. Thanks for it. 8) But it does not work yet when you try to set another image by using the SetGadgetState() function. It would be nice if you could solve it too.

Posted: Tue Mar 15, 2005 2:01 pm
by bender-rulez
Hi,

I tested the linux/beta libs and get some errors when I try to display ImageGadget or ButtonImageGadget

Code: Select all

(<unknown>:1892): Gdk-WARNING **: The gdk_draw_*_image require the drawable argument to
have a specified colormap. All windows have a colormap,
however, pixmaps only have colormap by default if they
were created with a non-NULL window argument. Otherwise
a colormap must be set on them with gdk_drawable_set_colormap

(<unknown>:1892): Gdk-WARNING **: Attempt to draw a drawable with depth 32 to a drawable with depth 24
my display is 24 bit cause the 16 bit bug, but now it seems it should be 32 bit???

the image is an indexed (256 color) bmp!

I´m using the -s gtk2 switch for compiling

Posted: Tue Mar 15, 2005 2:04 pm
by bender-rulez
the image example from purebasic does the same error!

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Image example file
;
;    (c) 2001 - Fantaisie Software
;
; ------------------------------------------------------------
;

If OpenWindow(0, 100, 100, 300, 300, #PB_Window_SystemMenu, "PureBasic - Image")

  Gosub CreateImage

  CreateGadgetList(WindowID())
    ImageGadget(0, 10, 10, 100, 100, ImageID())

  Repeat
    EventID = WaitWindowEvent()
  Until EventID = #PB_EventCloseWindow  ; If the user has pressed on the close button
  
EndIf

End   ; All the opened windows are closed automatically by PureBasic


;
; Some 2D graphics functions...
;

CreateImage:

  If CreateImage(0, 255, 255)
    If StartDrawing(ImageOutput())
        
      For k=0 To 255
        FrontColor(k,0, k)  ; a rainbow, from black to pink
        Line(0, k, 255, 0)
      Next

      DrawingMode(1)
      Locate(40, 50)
      FrontColor(255,255,255) ; print the text to white !
      DrawText("An image created easely...")

      StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
      
    EndIf  
  EndIf

Return

Code: Select all

(<unknown>:1952): Gdk-WARNING **: Attempt to draw a drawable with depth 32 to a drawable with depth 24
count = 1

Any hint?

Posted: Tue Mar 15, 2005 2:08 pm
by olejr
Works here with 24bit display..
Oh.. And all the betalibs installed..

Posted: Tue Mar 15, 2005 2:29 pm
by bender-rulez
ok, I found it, it´s the 'image' lib (gtk2) with the one from 3.92 it works under 24 bit without error message!

but I think it should even be fixed for 16 bit mode!