KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Image cropping

 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
pvds
KiXforms Follower
KiXforms Follower


Joined: 01 Apr 2003
Posts: 19
Location: Netherlands

PostPosted: Tue Oct 03, 2006 10:00 am    Post subject: Image cropping Reply with quote

Hi,

I am trying to get a pice of a picture in a new file.
I do not know how to use the new Graphics.DrawImage() control Shawn made.

Here is some code I use to figure it out the save to file part wil be a issue as well.

Code:
;region Script Settings
;<settings><scriptpackager><process>KIX32.EXE</process>
;<arguments></arguments>
;<extractdir>%TEMP%</extractdir>
;<outputdir>C:\FotoProg</outputdir>
;<files></files>
;<usedefaulticon>True</usedefaulticon>
;<icon></icon>
;<showinsystray>True</showinsystray>
;<tooltip></tooltip>
;<altcreds>False</altcreds>
;<efs>True</efs>
;<ntfs>True</ntfs>
;<local>False</local>
;<username></username>
;<domain></domain>
;<abortonfail>True</abortonfail>
;<product></product>
;<internalname></internalname>
;<version>1.0.0.1</version>
;<versionstring></versionstring>
;<description></description>
;<comments></comments>
;<company></company>
;</scriptpackager>
;</settings>
;
;endregion

Break On
$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

$Form1 = $System.Form()
$Form1.Left = 0
$Form1.StartPosition = 0  ;FormStartPosition_Manual
$Form1.Size = $System.Size(860,355) ;(Width,Height)
$Form1.Text = "Form1"
$Form1.Top = 0

$PictureBox1 = $System.PictureBox()
$PictureBox1.BorderStyle = 1  ;FixedSingle
$PictureBox1.Height = 307
$PictureBox1.Left = 10
$PictureBox1.SizeMode = 1  ;StretchImage
$PictureBox1.Top = 10
$PictureBox1.Width = 410
$PictureBox1.Image = $System.Bitmap.fromfile("C:\FotoProg\Els 021.jpg")
$nul = $Form1.Controls.Add($PictureBox1)

$PictureBox2 = $System.PictureBox()
$PictureBox2.BorderStyle = 1  ;FixedSingle
$PictureBox2.Height = 307
$PictureBox2.Left = 430
;$PictureBox2.SizeMode = 1  ;StretchImage
$PictureBox2.Top = 10
$PictureBox2.Width = 410
$PictureBox2.Image = $System.Graphics.DrawImage("C:\FotoProg\Els 021.jpg", 10,10,30,30)
$nul = $Form1.Controls.Add($PictureBox2)


;Graphics.DrawImage(image, dx,dy,dw,dh [, sx, sy, sw, sh] )

;sx, sy, sw, sh are the bits of the "source" image (specified using the "image" parm) ...
;the defaults are sx =0, sy = 0, sw = image width, sh = image height.

$Form1.Show  ;Displays the Form

While $Form1.Visible
   $Nul = Execute($Form1.DoEvents())
Loop
Exit 0


Thanks
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Tue Oct 03, 2006 12:47 pm    Post subject: Reply with quote

Here's an example of cropping a source image and saving it to a file:

Code:

Break On

$SOURCE_IMAGE = "c:\source.jpg"

$CROP_X = 30
$CROP_Y = 30
$CROP_WIDTH = 50
$CROP_HEIGHT = 50

$OUTPUT_IMAGE = "c:\target.jpg"

$System = CreateObject("Kixforms.System")

$SourceImage = $System.Image.FromFile($SOURCE_IMAGE)

$NewImage = $System.Bitmap.FromSize($System.Size($CROP_WIDTH,$CROP_HEIGHT))

$Graphics = $System.Graphics.FromImage($NewImage)

$Graphics.DrawImage($SourceImage,0,0,$NewImage.Width,$NewImage.Height,$CROP_X,$CROP_Y,$CROP_WIDTH,$CROP_HEIGHT)

$NewImage.Save($OUTPUT_IMAGE)

Exit 0
Back to top
View user's profile Send private message
pvds
KiXforms Follower
KiXforms Follower


Joined: 01 Apr 2003
Posts: 19
Location: Netherlands

PostPosted: Wed Oct 04, 2006 4:54 pm    Post subject: Reply with quote

Shawn

This helped a lot thanks, when we are done we wil post our script here.

Peter
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Wed Oct 04, 2006 4:57 pm    Post subject: Reply with quote

Your welcome ... let me know if you need any further enhancements.
Back to top
View user's profile Send private message
pvds
KiXforms Follower
KiXforms Follower


Joined: 01 Apr 2003
Posts: 19
Location: Netherlands

PostPosted: Sat Oct 07, 2006 4:40 pm    Post subject: Could use some help Reply with quote

Hi,

I made a script to cut a part out of a picture we made with a webcam the picture is made with Webcam Timershot from the MS powertoys (I do not know if this can be done with KiXforms.NET). I use KiXforms.NET for the first time and I am not convinced I am doing well.

In my form panel 2 can slide over Pane1 but they are not aligned, at the right and the bottom there is a problem panel2 is not completely visible on the edges. The code is far from finished but on these issues I can use some help. Embarassed

The code is also in the ZIP

Kind Regards,
Peter

Code:
Break On

$SourceBitmap = @SCRIPTDIR + "\Foto\My Pic.jpg"
$SourceBitmapE = @SCRIPTDIR + "\Foto\Leeg2.jpg"
$OutputBitmap = @SCRIPTDIR + "\Foto\"; + $Textbox1.Text +".jpg"

$System = CreateObject("Kixforms.System")

   $Form = $System.Form ; Create the Form
   $Form.ClientWidth = 600
   $Form.ClientHeight = 418
   
   $Timer1 = $System.timer() ; Create a timer
   $Timer1.Interval = 150
   $Timer1.Tick = "DrawPicture()"
      
   $Timer2 = $System.timer() ; Create a timer
   $Timer2.Interval = 500
   $Timer2.Tick = "Dir_Function()"
   $Timer2.Start
      
   $Panel1 = $Form.Controls.Add($System.Panel()) ; Create Panel1
   $Panel1.top = 10
   $Panel1.Left = 10
   $Panel1.Width = 400
   $Panel1.Height = 400
   $Panel1.BackColor = $System.Color.Green

   $Panel2 = $Form.Controls.Add($System.Panel()) ; Create Panel2
   $Panel2.Width = 86
   $Panel2.Height = 120
   $Panel2.Top = $Panel1.Top
   $Panel2.Left = $Panel1.Left
   $Panel2.BorderStyle = 1
   $Panel2.SizeMode = 1
   $Panel2.MouseMove = "PanelMouseMove($$System.Sender,$$System.EventArgs)"
   $Panel2.MouseLeave = "MouseLeave1()"
   
   $Button1 = $Form.Controls.Add($System.Button())
   $Button1.top = 30
   $Button1.Left = 430
   $Button1.Width = 50
   $Button1.Height = 20
   $Button1.Text = "Knip"
   $Button1.Click = "Save_Foto()"
   
   $Textbox1 = $Form.Controls.Add($System.TextBox())
   $Textbox1.top = 60
   $Textbox1.Left = 430
   $Textbox1.Width = 100
   $Textbox1.Text = "Nummer"
   
   $Label1 = $Form.Controls.Add($System.Label())
   $Label1.Text = ""
   $Label1.Top = 90
   $Label1.Left = 430
   $Label1.Width = 100
   
   $Form.Center
   $Form.Show
      
   While $Form.Visible
      $= Execute($Form.DoEvents)
   Loop

Exit 0

Function PanelMouseMove($Sender,$EventArgs)
   If ($Panel2.MouseButtons & $System.MouseButtons_Left)
      $Timer1.Start
      $Panel2.Left = $form.MousePosition.x - $Form.Left - $Panel2.Width
      $Panel2.Top = $form.MousePosition.y - $Form.Top - $Panel2.Height
   EndIf
EndFunction   

Function DrawPicture()
      $Bitmap = $System.Bitmap.FromSize($System.Size(400,400))
      $Graphics = $System.Graphics.FromImage($Bitmap)
      $Graphics.DrawImage($NewBitmap,0,0,$Panel2.Width,$Panel1.Height,$Panel2.Left,$Panel2.Top,$Panel2.Width,$Panel1.Height)
      $Panel2.BackgroundImage = $Bitmap
      $Timer1.Stop
EndFunction

Function MouseLeave1()
   If $Panel2.location.x < 10 Or $Panel2.location.x > $Panel1.Width - $Panel2.Width Or $Panel2.location.y < 10 Or $Panel2.location.y > $Panel1.Height - $Panel2.Height
      $Panel2.Top = $Panel1.Top
      $Panel2.Left = $Panel1.Left
   EndIf
EndFunction

Function Crop($OutputBitmap) ; From shawn

   $CROP_X = $Panel2.Left
   $CROP_Y = $Panel2.Top
   $CROP_WIDTH = $Panel2.Width
   $CROP_HEIGHT = $Panel2.Height
   
   $System = CreateObject("Kixforms.System")
   
   $SourceImage = $System.Image.FromFile($SourceBitmap)
   
   $NewImage = $System.Bitmap.FromSize($System.Size($CROP_WIDTH,$CROP_HEIGHT))
   
   $Graphics = $System.Graphics.FromImage($NewImage)
   
   $Graphics.DrawImage($SourceImage,$Panel1.Left,$Panel1.Top,$NewImage.Width,$NewImage.Height,$CROP_X,$CROP_Y,$CROP_WIDTH,$CROP_HEIGHT)
   
   $NewImage.Save($OutputBitmap)
   
   $Bitmap = ""

   $Timer2.start
   $Textbox1.Text = "Nummer"
EndFunction

Function Save_Foto()
      
   $check = Val($Textbox1.Text)
   
   If $check <> "" And Len($check) <> 6
      $TextBox1.Text = "Invul Fout"
      $TextBox1.SetFocus()
   Else
      If Exist($OutputBitmap  + $Textbox1.Text + ".jpg")
         $TextBox1.Text = "Bestaat al"
         $TextBox1.SetFocus()
      Else
         $ = Crop($OutputBitmap  + $Textbox1.Text + ".jpg")
         $Label1.Text = "Opgeslagen"
         
         $NewBitmap.dispose
         $OrgBitmap.dispose
         $Bitmap.dispose
         $OrgBitmapE.dispose
         $SourceImage.dispose
         $SourceBitmapE.dispose
         $OutputBitmap.dispose
         Del $SourceBitmap
         $Timer2.Start
      EndIf
   EndIf
EndFunction

Function Dir_Function()

   If Dir(@SCRIPTDIR + "\Foto\My Pic.jpg") <> ""
      $OrgBitmap = $System.Bitmap($SourceBitmap)
      $NewBitmap = $System.Bitmap.FromSize($System.Size(400,400))
      $NewGraphics = $System.Graphics.FromImage($NewBitmap)
      $NewGraphics.DrawImage($OrgBitmap,10,10,$NewBitmap.Width,$NewBitmap.Height)

      $Timer2.Stop
      $Bitmap = $System.Bitmap.FromSize($System.Size(400,400))
      $Graphics = $System.Graphics.FromImage($Bitmap)
      $Graphics.DrawImage($NewBitmap,10,10,400,400,$Panel1.Left,$Panel1.Top,$Panel1.Width,$Panel1.Height)
      $Panel1.BackgroundImage = $Bitmap
      $Panel1.BackgroundImage = $OrgBitmap
      $Panel2.show
      $Panel2.BringToFront()
      $Timer1.start
   Else
      $Panel2.hide
      $Label1.Text = "Wacht"
      $OrgBitmapE = $System.Bitmap($SourceBitmapE) ; Original Picture
      $Panel1.BackgroundImage = $OrgBitmapE
   EndIf

EndFunction



kix.zip
 Description:

Download
 Filename:  kix.zip
 Filesize:  54.25 KB
 Downloaded:  1041 Time(s)

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group