Page 1 of 1

image help

Posted: Thu Apr 24, 2008 1:29 pm
by abc123
how do i flip an image vertically and save it, any help?

Posted: Thu Apr 24, 2008 1:42 pm
by eesau
Please use the search feature before posting!

For flipping and mirroring images, look here.

Posted: Thu Apr 24, 2008 2:28 pm
by thefool
Old thingie dony by me, probably inspired by someone else but can't remember who. Long time ago

Code: Select all

ProcedureDLL imgm_MirrorImageY(image) 
  ; Mirrors an image around the Y-axis 

  Width = ImageWidth(image) 
  Height = ImageHeight(image) 
  hdc = StartDrawing(ImageOutput(image)) 
  StretchBlt_(hdc,0,Height,Width,-Height,hdc,0,0,Width,Height, #SRCCOPY) ; 
  StopDrawing() 
EndProcedure 

Code: Select all

ProcedureDLL imgm_MirrorImageX(image) 
  ; Mirrors an image around the X-axis 
  
  Width = ImageWidth(image) 
  Height = ImageHeight(image) 
  hdc = StartDrawing(ImageOutput(image)) 
  StretchBlt_(hdc,Width,0,-Width,Height,hdc,0,0,Width,Height, #SRCCOPY) ; 
  StopDrawing() 
EndProcedure 
and save it,
For loading and saving, check out the purebasic manual, it has some examples :)

Posted: Thu Apr 24, 2008 3:11 pm
by srod
Ah crap, that's a damn sight easier than the one I just came up with using GetDIBits_() and SetDIBits_() ! I forgot about StretchBlt_(), which is far more flexible than my method! :)

Doh!

Posted: Thu Apr 24, 2008 5:49 pm
by abc123
cant seem to get you procedures working, can supply an example please?

Posted: Thu Apr 24, 2008 5:55 pm
by srod
Works fine here. Just take care not to nest StartDrawing(). Personally I'd use a little more api to avoid this possibility.

Code: Select all

LoadImage(1, "bm2.bmp")

ProcedureDLL imgm_MirrorImageY(image) 
  ; Mirrors an image around the Y-axis 

  Width = ImageWidth(image) 
  Height = ImageHeight(image) 
  hdc = StartDrawing(ImageOutput(image)) 
  StretchBlt_(hdc,0,Height,Width,-Height,hdc,0,0,Width,Height, #SRCCOPY) ; 
  StopDrawing() 
EndProcedure 

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


  Repeat
    EventID = WaitWindowEvent()
    
    If EventID = #PB_Event_Repaint
      ;Draw the original image.
        StartDrawing(WindowOutput(0))
          DrawImage(ImageID(1), 0, 0)
        StopDrawing()    
      ;Draw the original image.
        imgm_MirrorImageY(1)
        StartDrawing(WindowOutput(0))
          DrawImage(ImageID(1), 100, 0)
        StopDrawing()    
    EndIf
    
  Until EventID = #PB_Event_CloseWindow  ; If the user has pressed on the close button
  
EndIf

Posted: Thu Apr 24, 2008 6:17 pm
by abc123
how can i save the flipped image?

Posted: Thu Apr 24, 2008 6:25 pm
by Fluid Byte
RTFM would help.

Posted: Fri Apr 25, 2008 10:53 am
by thefool
Fluid Byte wrote:RTFM would help.
i did tell him the nice way first. But oh well:
Result = SaveImage(#Image, FileName$ [, ImagePlugin [, Flags]])


Saves the specified #Image to disk. By default, the saved image will be in 24bit BMP format. If function fails, 0 is returned, else all is fine. 'ImagePlugin' is an optional parameter and can be one of the following constant:
#PB_ImagePlugin_BMP : Save the image in BMP.
#PB_ImagePlugin_JPEG : Save the image in JPEG (the function UseJPEGImageEncoder() must be used)
#PB_ImagePlugin_PNG : Save the image in PNG (the function UsePNGImageEncoder() must be used)

'Flags' is an optional parameter depending of the plugin used. For now, only the quality setting is supported: a number from 0 (worste quality) to 10 (maximum quality). Only the JPEG plugin currently support it (default quality is set to '7' if no flags are specified with the JPEG encoder).
In srods example, saveimage(1,"test.bmp")
thefool wrote: For loading and saving, check out the purebasic manual, it has some examples
come on, you got nearly 200 posts, you should be able to read the manual by now!

oh and you can remove the "DLL" after "procedure", that was because i wrote the functions for a library.