ResizeImage() "fault" or did i miss somthing?

Just starting out? Need help? Post your questions and find answers here.
harry57
New User
New User
Posts: 3
Joined: Sat May 31, 2003 1:33 am
Location: UK

ResizeImage() "fault" or did i miss somthing?

Post by harry57 »

Is there something wrong with this code?

Code: Select all


If InitSprite()
  If OpenWindow(0,0,0,100,100,"Icon Test",#PB_Window_TitleBar|#PB_Window_MinimizeGadget|#PB_Window_SystemMenu)
    If OpenWindowedScreen(WindowID(0),0,0,WindowWidth(0),WindowHeight(0),0,0,0)
      If LoadImage(0,"MouseUp_16x16.ico")
        If CopyImage(0,1)
          If ResizeImage(1,32,32,#PB_Image_Smooth)
            ;ResizeImage(1,32,32,#PB_Image_Smooth)
            If StartDrawing(ScreenOutput())
              DrawImage(ImageID(0),0,0)
              DrawImage(ImageID(1),0,20)
              StopDrawing()
              While WaitWindowEvent()<>#PB_Event_CloseWindow : Wend
            Else
              Debug "Failed to init Drawing"
            EndIf
          Else
            Debug "Failed to resize Image"
          EndIf
          FreeImage(1)
        Else
          Debug "Failed to copy Image"
        EndIf
        FreeImage(0)
      Else
        Debug "Failed to load Image"
      EndIf
      CloseScreen()
    Else
      Debug "Failed to open windowed Screen"
    EndIf
    CloseWindow(0)
  Else
    Debug "Failed to open Window"
  EndIf
Else
  Debug "InitSprite() failed"
EndIf
End
or is ther something wrong with "Resize()" in PB 4?
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

PB only resizes Bitmap images... It doesn't work with icons or cursors yet

Dri :(
User avatar
Michael Vogel
Addict
Addict
Posts: 2807
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: ResizeImage() "fault" or did i miss somthing?

Post by Michael Vogel »

harry57 wrote:[...]or is ther something wrong with "Resize()" in PB 4?
Resize is definitely buggy - because it does produce wrong (or empty) pictures on some graphic cards!

I fear, we've to wait until fred has again more time for the windows version, in the meantime I used the DrawImage() function, which also fails on certain images in graphic modes less 32 bits.

See also my function Scale() in http://www.purebasic.fr/english/viewtopic.php?t=22668

Michael
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Dr Dri is correct about the .ico image format. You can work with icons natively in PB if you want to avoid using the DrawIconEx_() API, but you will have to employ a tiny workaround to "clean up" the format of the loaded image first:

Code: Select all

;replace CopyImage(0,1) with:
CreateImage(1,ImageWidth(0),ImageHeight(0))
StartDrawing(ImageOutput(1))
  DrawImage(ImageID(0),0,0)
StopDrawing()
Once you've done this the ResizeImage should work correctly.
BERESHEIT
harry57
New User
New User
Posts: 3
Joined: Sat May 31, 2003 1:33 am
Location: UK

Re: ResizeImage() "fault" or did i miss somthing?

Post by harry57 »

Thaks netmeastro, for your little Workaround, works a treat! :D
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

"pb's" resize is just gdi in windows.
User avatar
Michael Vogel
Addict
Addict
Posts: 2807
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

superadnim wrote:"pb's" resize is just gdi in windows.
doesn't seem so, with other programming languages (hopefully using the API) I never had these problems...

...and believe me, I tried a lot of things (maybe they have all been wrong) to get images correctly resized, like the following:

Code: Select all

; offen:	Dekstop-Tiefe ohne ExamineDesktops
; gelöst:	Überblenden geht nicht (Schatten des letzten Bilds)
; offen:	Resize-Fehler

;{
  Global ScreenX=1024;GetSystemMetrics_(#SM_CXSCREEN)
  Global ScreenY=768;GetSystemMetrics_(#SM_CYSCREEN)
  Global FrameSizeX=ScreenX*0.72;640
  Global FrameSizeY=ScreenY*0.74;0.9;540

  Structure PictStruct
    id.l
    x.l
    y.l
    w.l
    h.l
  EndStructure

  Global Dim Picture.PictStruct(1)

;}

Procedure ScalePicture(n)
  Protected factor.f


  Picture(n)\w=ImageWidth(n)
  Picture(n)\h=ImageHeight(n)

  If Picture(n)\w>FrameSizeX
    factor=FrameSizeX/Picture(n)\w
    Picture(n)\w*factor
    Picture(n)\h*factor
  EndIf
  If Picture(n)\h>FrameSizeY
    factor.f=FrameSizeY/Picture(n)\h
    Picture(n)\w*factor
    Picture(n)\h*factor
  EndIf

  Picture(n)\id=ImageID(n)
  Picture(n)\x=(ScreenX-Picture(n)\w)>>1
  Picture(n)\y=(ScreenY-Picture(n)\h)>>1

  ; DOES NOT WORK!!!!!
  ;ResizeImage(n,Picture(n)\w,Picture(n)\h,#PB_Image_Smooth)

  If IsSprite(n) : FreeSprite(n) : EndIf
  CreateSprite(n,Picture(n)\w,Picture(n)\h,#PB_Sprite_Texture)

  ; "Workaround"...
  StartDrawing(SpriteOutput(n))
  ; DOES NOT WORK WITH CERTAIN PICTURES
  ; - even when used with 32 bit colors - small black rectangles at the top etc.
  ; - but more problems with 16/24 bit modes - strange stripes etc.

  DrawImage(Picture(n)\id,0,0,Picture(n)\w,Picture(n)\h); because Resize doesn't work
  StopDrawing()

  If IsSprite3D(n) : FreeSprite3D(n) : EndIf
  CreateSprite3D(n,n)

EndProcedure

UseJPEGImageDecoder()
If (InitSprite() And InitSprite3D())
  If OpenScreen(ScreenX,ScreenY,32,"Diashow")

    ; ////////
    LoadImage(0,"E:\Programs\Prog\Source\!Fade\CIMG0172.jpg",#PB_Image_DisplayFormat)
    ; ///////

    ; /////////////////
    x=2
    ; /////////////////
    FlipBuffers()

    Select x
    Case 1
      ; here's everything ok...
      StartDrawing(ScreenOutput())
      DrawImage(ImageID(0),0,0,Picture(n)\w,Picture(n)\h)
      StopDrawing()
    Case 2
      ; this picture already does not look perfect
      ScalePicture(0)
      StartDrawing(ScreenOutput())
      DrawImage(Picture(n)\id,0,0);,Picture(n)\w,Picture(n)\h)
      StopDrawing()
    Case 3
      ; target - for fade effect in dia show
      ScalePicture(0)
      Start3D()
      DisplaySprite3D(0,Picture(0)\x,Picture(0)\y,255)
      Stop3D()
    EndSelect

    FlipBuffers()

    Delay(5000)
  EndIf
EndIf
Result:
Image
(http://sudokuprogram.googlepages.com/CIMG0172.jpg) will be resized into something like
Image
(http://sudokuprogram.googlepages.com/ResizeError.jpg)!

No I really have no more ideas, what to do...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Michael Vogel wrote:
superadnim wrote:"pb's" resize is just gdi in windows.
doesn't seem so
I can assure you, superadnim is right.
User avatar
Michael Vogel
Addict
Addict
Posts: 2807
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Trond wrote:
Michael Vogel wrote:
superadnim wrote:"pb's" resize is just gdi in windows.
doesn't seem so
I can assure you, superadnim is right.
So the API produces different results when using ResizeImage() or DrawImage([...],sizex,sizey)?

I'll do a last try this weekend - hopefully I've a little bit time to do some further checks (in the meantime I used already 4 different notebooks which all "produce" different results... - only the ResizeImage() command is stable - and fails completely on all notebooks!)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Michael Vogel wrote:
Trond wrote:
Michael Vogel wrote:
superadnim wrote:"pb's" resize is just gdi in windows.
doesn't seem so
I can assure you, superadnim is right.
So the API produces different results when using ResizeImage() or DrawImage([...],sizex,sizey)?

I'll do a last try this weekend - hopefully I've a little bit time to do some further checks (in the meantime I used already 4 different notebooks which all "produce" different results... - only the ResizeImage() command is stable - and fails completely on all notebooks!)
I've got some other problems with the ResizeImage(), Fred said that this: "Here we got a problem, as stretchblt() doesn't work properly with 32 bits bitmaps if the HALFTONE property is set..".

If you get different results with api and pb it is most likely because you use different parameters. Have you tried #PB_Image_Raw? It seems to work better here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2807
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Trond wrote:Have you tried #PB_Image_Raw? It seems to work better here.
Not for now (see last listing), but I'll try that also (free time of weekend gets shorter and shorter;) -- Thank you for the tip :)

maybe someone will be that keen to write a nice assembler procedure for resizing images 8)
SoulReaper
Enthusiast
Enthusiast
Posts: 372
Joined: Sun Apr 03, 2005 2:14 am
Location: England

Post by SoulReaper »

Hello

I know this might be silly but I was talking to a friend about your problem with Resize Image and he said about StretchBlt_() instead. oh with halftone...

Maybe StretchBlt_() is the answer to the problem with Resize Image...

Hope I understood the Problem correct :wink:

sorry it was talked about above by Trond :oops:

Regards
Kevin :)
Post Reply