Page 1 of 1

Stretched image - How do I get around this problem?

Posted: Sat Aug 14, 2004 4:55 pm
by syntax error
I want to draw a stretched image into a window or image gadget.
I'm using DrawImages extra NeWidth/NeHeight parameters but I'm getting an anti-alias type of effect appearing in the image:

Image

The circle needs to show without the anti-alias effect.

Code example for above:

Code: Select all

ball.l=CreateImage(#pb_any,16,16)
UseImage(ball)
StartDrawing(ImageOutput())
Box(0,0,26,26,RGB(255,255,255))
DrawingMode(4)
Circle(8,8,7,RGB(20,10,95))
StopDrawing()

#wflags=#PB_Window_SystemMenu |#PB_Window_TitleBar
OpenWindow(0,50,160,280,300,#wflags,"Stretched image")

StartDrawing(WindowOutput())
DrawImage(UseImage(ball),10,10 , 250,250)
StopDrawing()

Repeat
  ev=WaitWindowEvent()
Until ev=#PB_EventCloseWindow

End
Any other commands/flags I might have missed?

Posted: Sat Aug 14, 2004 5:47 pm
by GreenGiant
Here, this code isnt very elegant, but its working for me.

Code: Select all

ball.l=CreateImage(#pb_any,16,16) 
UseImage(ball) 
StartDrawing(ImageOutput()) 
Box(0,0,26,26,RGB(255,255,255)) 
DrawingMode(4) 
Circle(8,8,7,RGB(20,10,95)) 
StopDrawing() 

#wflags=#PB_Window_SystemMenu |#PB_Window_TitleBar 
OpenWindow(0,50,160,280,300,#wflags,"Stretched image") 

StartDrawing(WindowOutput()) 
DrawImage(UseImage(ball),10,10 );, 250,250) 
StopDrawing()

hDc=StartDrawing(WindowOutput())
StretchBlt_(hDc,10,10,250,250,hDc,10,10,16,16,#SRCCOPY)
StopDrawing()


Repeat 
  ev=WaitWindowEvent() 
Until ev=#PB_EventCloseWindow 

End
Ideally, you'd be copying from the image Device Context, not from the window to the window, but I couldnt get it to work, so this is the workaround.

Posted: Sat Aug 14, 2004 5:50 pm
by J. Baker
This might be hard in any programming language. If you ever used a paint program, which I'm sure you have and resized an image. The pixels always create some kind of distorsion wether it's scaled up or down. The only way to get somewhat of an accurate image would be to have for every pixel times four, when resized.

EDIT
GreenGiant must have posted the same time I did. Nice work GreenGiant!

Posted: Sun Aug 15, 2004 7:36 am
by syntax error
I tried the StretchBlt_ method before but using an ImageGadget()
However, nothing shows up.
Here, I'm trying to get the #ball image to appear in the #canvas ..

Code: Select all

Enumeration
  #win
  #canvasgadget
  #ball
  #canvas
EndEnumeration

CreateImage(#ball,16,16)
CreateImage(#canvas,256,256)

UseImage(#ball) 
*hdcSource=StartDrawing(ImageOutput())
Box(0,0,26,26,RGB(255,255,255)) 
DrawingMode(4) 
Circle(8,8,7,RGB(20,10,95)) 
StopDrawing() 

UseImage(#canvas)
*hdcDest=StartDrawing(ImageOutput())
Box(0,0,256,256,RGB(50,70,90))
StopDrawing()

StretchBlt_(*hdcDest,0,0,256,256,*hdcSource,0,0,16,16,#SRCCOPY) 


#wflags=#PB_Window_SystemMenu |#PB_Window_TitleBar 
OpenWindow(#win,50,160,280,280,#wflags,"StretchBlt example")
CreateGadgetList(WindowID())
ImageGadget(#canvasgadget,8,8,256,256,UseImage(#canvas),#PB_Image_Border)


Repeat 
  ev=WaitWindowEvent() 
Until ev=#PB_EventCloseWindow 

End
Any ideas?


EDIT

Resolved by drawing the ball to the canvas then using StretchBlt_ to stretch the image within the canvas.
StretchBlt_ fails when trying to stretch an image from a different source.

Now working ...

Code: Select all

Enumeration
  #win
  #canvasgadget
  #ball
  #canvas
EndEnumeration

CreateImage(#ball,16,16)
CreateImage(#canvas,256,256)

UseImage(#ball) 
hdcSource=StartDrawing(ImageOutput())
Box(0,0,26,26,RGB(255,255,255)) 
DrawingMode(4) 
Circle(8,8,7,RGB(20,10,95)) 
StopDrawing() 

UseImage(#canvas)
hDC=StartDrawing(ImageOutput())
Box(0,0,256,256,RGB(50,70,90))
DrawImage(UseImage(#ball),0,0)
result=StretchBlt_(hDC,0,0,256,256,hDC,0,0,16,16,#SRCCOPY)
StopDrawing()



;- gui
#wflags=#PB_Window_SystemMenu |#PB_Window_TitleBar 
OpenWindow(#win,50,160,280,280,#wflags,"StretchBlt example")
CreateGadgetList(WindowID())
ImageGadget(#canvasgadget,8,8,256,256,UseImage(#canvas),#PB_Image_Border)

;- main
Repeat 
  ev=WaitWindowEvent() 
Until ev=#PB_EventCloseWindow 

End
Thankyou for your assistance.
Much appreciated as always.

Posted: Sun Aug 15, 2004 1:40 pm
by MikeB
I had exactly the same problem a little while ago and Danilo was kind enough to give me the solution which I am sure he will not mind my passing on.

Code: Select all

Procedure ResizeImage_NoAntialias(image,w,h) 
    ; 
    ; resize PB image without antialiasing 
    ; 
    ; by Danilo, 17.01.2004 - english forum 
    ; 
    hBmp_orig = UseImage(image) 
    Width    = ImageWidth() 
    Height   = ImageHeight() 
    hDesk = GetDesktopWindow_() 
    hDC_orig = GetWindowDC_(hDesk) 
    If hDC_orig 
        hDC = CreateCompatibleDC_(hDC1) 
        If hDC 
            hBmp = CreateCompatibleBitmap_(hDC_orig,Width,Height) 
            If hBmp 
                SelectObject_(hDC,hBmp) 
                hDC_orig = StartDrawing(ImageOutput()) 
                If hDC_orig 
                    BitBlt_(hDC,0,0,Width,Height,hDC_orig,0,0,#SRCCOPY) 
                    StopDrawing() 
                    hBmp_orig = CreateImage(image,w,h) 
                    hDC_orig  = StartDrawing(ImageOutput()) 
                    If hDC_orig 
                        StretchBlt_(hDC_orig,0,0,w,h,hDC,0,0,Width,Height,#SRCCOPY) 
                        StopDrawing() 
                        Result = #True 
                    EndIf 
                EndIf 
                DeleteObject_(hBmp) 
            EndIf 
            DeleteDC_(hDC) 
        EndIf 
        ReleaseDC_(hDesk,hDC_orig) 
    EndIf 
    ProcedureReturn Result 
EndProcedure 
Thanks again Danilo

MikeB