image help

Just starting out? Need help? Post your questions and find answers here.
abc123
Enthusiast
Enthusiast
Posts: 195
Joined: Wed Apr 18, 2007 9:27 pm

image help

Post by abc123 »

how do i flip an image vertically and save it, any help?
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

Please use the search feature before posting!

For flipping and mirroring images, look here.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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 :)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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!
I may look like a mule, but I'm not a complete ass.
abc123
Enthusiast
Enthusiast
Posts: 195
Joined: Wed Apr 18, 2007 9:27 pm

Post by abc123 »

cant seem to get you procedures working, can supply an example please?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
abc123
Enthusiast
Enthusiast
Posts: 195
Joined: Wed Apr 18, 2007 9:27 pm

Post by abc123 »

how can i save the flipped image?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

RTFM would help.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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.
Post Reply