Form any image Tech.

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Form any image Tech.

Post by RASHAD »

Hi
Simple as usual using native commands
Form any image in any shape tech.

Code: Select all

UseTGAImageDecoder()
UseGIFImageDecoder()
UseJPEG2000ImageDecoder()
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()

Global fimg

Procedure Rotate(img,ww,hh,Deg)
  fimg = CreateImage(#PB_Any,ww*Cos(Radian(deg)) + hh*Sin(Radian(deg)),hh*Cos(Radian(deg))+ ww*Sin(Radian(deg)),32)  
  StartVectorDrawing(ImageVectorOutput(fimg))
    VectorSourceColor($FFFFFFFF)
    FillVectorOutput()
    ResetCoordinates()
    MovePathCursor(hh*Sin(Radian(deg)),0)   
    RotateCoordinates(ww*Sin(Radian(deg)),0,deg)
    DrawVectorImage(ImageID(img), 255)
  StopVectorDrawing()
  ProcedureReturn fimg
EndProcedure

OpenWindow(0, 0, 0, 800, 600, "Screen", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(0,10,10,780,550)

ContainerGadget(3,10,570,120,20)
  SpinGadget(1,0,0,40,20,2,10,#PB_Spin_Numeric)
  SetGadgetState(1,2)
  ButtonGadget(2,50,0,60,20,"RUN")
CloseGadgetList()

Repeat
  Select WaitWindowEvent(1)
    Case #PB_Event_CloseWindow
      End

    Case #PB_Event_Gadget
      Select EventGadget()
        Case 2
          FileName$ = OpenFileRequester("SELECT IMAGE","","All supported formats|*.bmp;*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.tga|TGA image (*.tga)|*.tga|TIF image (*.tif)|*.tif|TIFF image (*.tiff)|*.tiff|PNG image (*.png)|*.png|BMP image (*.bmp)|*.bmp|JPEG image (*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF image (*.gif)|*.gif",0)
          If FileName$
            LoadImage(0,FileName$)
            width = ImageWidth(0)
            height = ImageHeight(0)
            Rotate(0,width,height,35)
            width = ImageWidth(fimg)
            height = ImageHeight(fimg)
            ResizeWindow(0,0,0,width+20,height+50)
            HideWindow(0,0,#PB_Window_ScreenCentered)
            ResizeGadget(0,10,10,width,height)
            ResizeGadget(3,10,height+20,120,20)
            dif = GetGadgetState(1)
            dif2 = dif/2
            CreateImage(1,width,height,32,$FFFFFF)
            StartDrawing(ImageOutput(1))
            For h = 0 To height-1
              GrabImage(fimg,2,0,h,width,1)
              DrawingMode(#PB_2DDrawing_AlphaBlend)
              DrawImage(ImageID(2),h/dif,h,width-h/dif2,1)
            Next
            StopDrawing()  
            SetGadgetAttribute(0,#PB_Canvas_Image ,ImageID(1))
          EndIf
      EndSelect
  EndSelect
ForEver
Edit :Modified,fixed some bugs & Added Rotate to show clearly the effect
Last edited by RASHAD on Sun Jun 10, 2018 12:27 pm, edited 1 time in total.
Egypt my love
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Form any image Tech.

Post by Kwai chang caine »

Hello RASHAD
I don't know if it's the effect wanted, but i see just a part of image and i have not understand the founction of spiner :oops:
ImageThe happiness is a road...
Not a destination
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Form any image Tech.

Post by RASHAD »

Hi KCC
Previous post updated
You can play with it to put any image in any shape you like (circle ,trapezoidal ,diamond ...etc)
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Form any image Tech.

Post by RASHAD »

Example #1:
Diamond

Code: Select all

UseTGAImageDecoder()
UseGIFImageDecoder()
UseJPEG2000ImageDecoder()
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()

OpenWindow(0, 0, 0, 800, 600, "Screen", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(0,10,10,780,550)

ContainerGadget(3,10,570,120,20)
  ButtonGadget(2,0,0,60,20,"RUN")
CloseGadgetList()

Repeat
  Select WaitWindowEvent(1)
    Case #PB_Event_CloseWindow
      End

    Case #PB_Event_Gadget
      Select EventGadget()
        Case 2
          FileName$ = OpenFileRequester("SELECT IMAGE","","All supported formats|*.bmp;*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.tga|TGA image (*.tga)|*.tga|TIF image (*.tif)|*.tif|TIFF image (*.tiff)|*.tiff|PNG image (*.png)|*.png|BMP image (*.bmp)|*.bmp|JPEG image (*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF image (*.gif)|*.gif",0)
          If FileName$
            LoadImage(0,FileName$)
            If ImageWidth(0) < ImageHeight(0)
              w = ImageWidth(0)
            Else
              w = ImageHeight(0)
            EndIf
            ResizeImage(0,w,w)
            ResizeWindow(0,0,0,w+20,w+50)
            HideWindow(0,0,#PB_Window_ScreenCentered)
            ResizeGadget(0,10,10,w,w)
            ResizeGadget(3,10,w +20,120,20)
            CreateImage(1,w,w,32,$FFFFFF)
            StartDrawing(ImageOutput(1))
            For h = 0 To w-1
              GrabImage(0,2,0,h,w,1)
              DrawingMode(#PB_2DDrawing_AlphaBlend)
              xx = Abs(w/2-h)
              ww = Abs(w/2-xx)
              DrawImage(ImageID(2),xx,h,2*ww,1)
            Next
            StopDrawing()  
            SetGadgetAttribute(0,#PB_Canvas_Image ,ImageID(1))
          EndIf
      EndSelect
  EndSelect
ForEver
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Form any image Tech.

Post by RASHAD »

Example #2:
Circle

Code: Select all

UseTGAImageDecoder()
UseGIFImageDecoder()
UseJPEG2000ImageDecoder()
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()

OpenWindow(0, 0, 0, 800, 600, "Screen", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(0,10,10,780,550)

ContainerGadget(3,10,570,120,20)
  ButtonGadget(2,0,0,60,20,"RUN")
CloseGadgetList()

Repeat
  Select WaitWindowEvent(1)
    Case #PB_Event_CloseWindow
      End

    Case #PB_Event_Gadget
      Select EventGadget()
        Case 2
          FileName$ = OpenFileRequester("SELECT IMAGE","","All supported formats|*.bmp;*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.tga|TGA image (*.tga)|*.tga|TIF image (*.tif)|*.tif|TIFF image (*.tiff)|*.tiff|PNG image (*.png)|*.png|BMP image (*.bmp)|*.bmp|JPEG image (*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF image (*.gif)|*.gif",0)
          If FileName$
            LoadImage(0,FileName$)
            If ImageWidth(0) < ImageHeight(0)
              w = ImageWidth(0)
            Else
              w = ImageHeight(0)
            EndIf
            ResizeImage(0,w,w)
            ResizeWindow(0,0,0,w+20,w+50)
            HideWindow(0,0,#PB_Window_ScreenCentered)
            ResizeGadget(0,10,10,w,w)
            ResizeGadget(3,10,w +20,120,20)
            CreateImage(1,w,w,32,$FFFFFF)
            StartDrawing(ImageOutput(1))
            For h = 1 To w
              GrabImage(0,2,0,h,w,1)
              DrawingMode(#PB_2DDrawing_AlphaBlend)
              xx = Sqr(Pow(w/2,2)-Pow((w/2-h),2))
              xx = Abs(w/2-xx)
              DrawImage(ImageID(2),xx,h,w-2*xx,1)
            Next
            StopDrawing()  
            SetGadgetAttribute(0,#PB_Canvas_Image ,ImageID(1))
          EndIf
      EndSelect
  EndSelect
ForEver
Egypt my love
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Form any image Tech.

Post by RSBasic »

@RASHAD
Nice codes. 8)
Image
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Form any image Tech.

Post by Kwai chang caine »

Aaaaah !!! yes i have understand now :D
Somes pictures are really funny after passing in your :lol:

Image

The image are always more big than the screen :wink:
Thanks a lot for this codes 8)
ImageThe happiness is a road...
Not a destination
Post Reply