View previous topic :: View next topic |
Author |
Message |
pvds KiXforms Follower

Joined: 01 Apr 2003 Posts: 19 Location: Netherlands
|
Posted: Mon Oct 09, 2006 5:17 pm Post subject: Help wanted |
|
|
Hi,
Can someone help me to solve this!
After saving a jpg file I want to delete the original I use Dispose but somehow I am not lucky.
problem is in the SaveImage function
Please Help
Code: | Break On
$Rect_Width = 100
$Rect_Height = 100
$Photo = @SCRIPTDIR + "\Foto\lara.jpg"
$New_PhotoPath = @SCRIPTDIR + "\Foto\"
$Empty_Photo = @SCRIPTDIR + "\Foto\Leeg2.jpg"
$System = CreateObject("Kixforms.System")
;$Bitmap = $System.Bitmap($Photo)
$Form = $System.Form
$Form.ClientWidth = 400
$Form.ClientHeight = 600
$Timer1 = $System.timer() ; Create a timer
$Timer1.Interval = 150
$Timer1.Tick = "Check_Photo()"
$Panel1 = $Form.Controls.Add($System.Panel())
$Panel1.Top = 0
$Panel1.Left = 0
$Panel1.Width = 400
$Panel1.Height = 400
$Panel1.BackColor = $System.Color.red
$Panel1.MouseMove = "PanelMouseMove($$System.Sender,$$System.EventArgs)"
$Button1 = $Form.Controls.Add($System.Button())
$Button1.Top = 410
$Button1.Left = 10
$Button1.Text = "Opslaan"
$Button1.Click = "SaveImage($MouseX, $MouseY)"
$Button1.Width = 150
$TextBox1 = $Form.Controls.Add($System.TextBox())
$TextBox1.Top = $Button1.Top + 30
$TextBox1.Left = $Button1.Left
$TextBox1.Text = Nummer
$Label1 = $Form.Controls.Add($System.Label())
$Label1.Top = $Button1.Top + 60
$Label1.Left = $Button1.Left
$Label1.Text = ""
$Label1.Width = 150
$Timer1.Start
;Draw_Rect(0 - $Rect_Width - 10,0)
$Form.Center
$Form.Show
While $Form.Visible
$= Execute($Form.DoEvents)
Loop
Exit 0
Function Draw_Rect($MouseX, $MouseY)
$Bitmap = $System.Bitmap($Photo);
$Plaatje = $System.Graphics.FromImage($Bitmap)
If ($Bitmap <> "")
$Plaatje.DrawRectangle($System.Pen($System.Color.DarkSlateBlue,3),$MouseX,$MouseY,$Rect_Width,$Rect_Height);
$Panel1.BackgroundImage = $Bitmap
$Bitmap = $System.Bitmap($Photo)
$Panel1.Refresh()
EndIf
EndFunction
Function PanelMouseMove($Sender,$EventArgs)
If ($Panel1.MouseButtons & $System.MouseButtons_Left)
$MouseY = $Panel1.MousePosition.y - $form.top - 20
$MouseX = $Panel1.MousePosition.x - $form.Left - $panel1.Left
Draw_Rect($MouseX, $MouseY)
EndIf
EndFunction
Function SaveImage($MouseX, $MouseY)
$check = Val($Textbox1.Text)
If $check = 0 Or Len($check) <> 6
$Label1.Text = "Invul Fout"
Else
If Exist($New_PhotoPath + $Textbox1.Text + ".jpg")
$Label1.Text = "Foto al aanwezig!"
Else
$Timer1.stop
$NewImage = $Bitmap.Clone($MouseX,$MouseY,$Rect_Width,$Rect_Height)
$NewImage.Save($New_PhotoPath + $TextBox1.Text + ".jpg")
$Label1.Text = "Opgeslagen: " + $TextBox1.Text
$TextBox1.Text = "Nummer"
;$System.Pen.Dispose
;? @ERROR
$Bitmap.Dispose
? @ERROR
$NewImage.Dispose
? @ERROR
Del $Photo
? @ERROR
$Panel1.Refresh()
$Timer1.start
EndIf
EndIf
EndFunction
Function Check_Photo()
If Dir($Photo) <> ""
$Timer1.Stop
Draw_Rect($MouseX, $MouseY)
Else
$Label1.Text = "Wacht"
EndIf
EndFunction |
|
|
Back to top |
|
 |
Gargoyle KiXforms Aficionado


Joined: 30 Dec 2003 Posts: 366 Location: Arizona
|
Posted: Mon Oct 09, 2006 5:55 pm Post subject: |
|
|
Are you wanting to get rid of the image on screen, or are you wanting to actually delete the original file? _________________ Parents were invented to make children happy by giving them something to ignore. |
|
Back to top |
|
 |
pvds KiXforms Follower

Joined: 01 Apr 2003 Posts: 19 Location: Netherlands
|
Posted: Mon Oct 09, 2006 6:09 pm Post subject: |
|
|
Gargoyle wrote: | Are you wanting to get rid of the image on screen, or are you wanting to actually delete the original file? |
I want to delete de actual file and wait for the next file to load from a webcam. Everything is working accept the simple deleting of this file. GRRRR |
|
Back to top |
|
 |
Gargoyle KiXforms Aficionado


Joined: 30 Dec 2003 Posts: 366 Location: Arizona
|
Posted: Mon Oct 09, 2006 8:09 pm Post subject: |
|
|
Saw your post on KORG, and you said that you are recieving error 32..
Quote: | The process cannot access the file because it is being used by another process. |
You need to close the file in the script so that KiX can then delete it.
Try this...
Code: |
Function SaveImage($MouseX, $MouseY)
$check = Val($Textbox1.Text)
If $check = 0 Or Len($check) <> 6
$Label1.Text = "Invul Fout"
Else
If Exist($New_PhotoPath + $Textbox1.Text + ".jpg")
$Label1.Text = "Foto al aanwezig!"
Else
$Timer1.stop
$NewImage = $Bitmap.Clone($MouseX,$MouseY,$Rect_Width,$Rect_Height)
$NewImage.Save($New_PhotoPath + $TextBox1.Text + ".jpg")
$Label1.Text = "Opgeslagen: " + $TextBox1.Text
$TextBox1.Text = "Nummer"
$Bitmap =""
;$System.Pen.Dispose
;? @ERROR
$Bitmap.Dispose
? @ERROR
$NewImage.Dispose
? @ERROR
Del $Photo
? @ERROR
$Panel1.Refresh()
$Timer1.start
EndIf
EndIf
EndFunction
|
_________________ Parents were invented to make children happy by giving them something to ignore. |
|
Back to top |
|
 |
pvds KiXforms Follower

Joined: 01 Apr 2003 Posts: 19 Location: Netherlands
|
Posted: Mon Oct 09, 2006 8:24 pm Post subject: |
|
|
Gargoyle,
I tried that one already no luck!
It is something else and I can not find it. GRRR
Thanks,
Peter |
|
Back to top |
|
 |
benny69 KiXforms Advocate


Joined: 30 Oct 2003 Posts: 567 Location: Lincoln, Ne
|
Posted: Mon Oct 09, 2006 9:45 pm Post subject: |
|
|
Try
$Bitmap = 0
$NewImage = 0
instead of
$Bitmap.Dispose
$NewImage.Dispose _________________ Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta) |
|
Back to top |
|
 |
benny69 KiXforms Advocate


Joined: 30 Oct 2003 Posts: 567 Location: Lincoln, Ne
|
Posted: Mon Oct 09, 2006 9:48 pm Post subject: |
|
|
never mind, just saw your post over at korg. _________________ Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta) |
|
Back to top |
|
 |
pvds KiXforms Follower

Joined: 01 Apr 2003 Posts: 19 Location: Netherlands
|
Posted: Mon Oct 09, 2006 9:49 pm Post subject: |
|
|
Hi,
I tried
$bitmap = ""
$bitmap = 0
$bitmap.dispose
This is not working
Maby ther is something with the DrawRectangle or PEN thing. |
|
Back to top |
|
 |
benny69 KiXforms Advocate


Joined: 30 Oct 2003 Posts: 567 Location: Lincoln, Ne
|
Posted: Mon Oct 09, 2006 9:51 pm Post subject: |
|
|
maybe if you,
dim $bitmap,$newimage
at the begining of the saveimage function _________________ Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta) |
|
Back to top |
|
 |
pvds KiXforms Follower

Joined: 01 Apr 2003 Posts: 19 Location: Netherlands
|
Posted: Mon Oct 09, 2006 10:02 pm Post subject: |
|
|
It did not help in the morning I wil giv it a new look.
Thanks
Peter |
|
Back to top |
|
 |
Gargoyle KiXforms Aficionado


Joined: 30 Dec 2003 Posts: 366 Location: Arizona
|
Posted: Mon Oct 09, 2006 11:00 pm Post subject: |
|
|
You may want to completly destroy the form.. After you do a save try...
Code: |
$system = ""
Del $photo
$System = CreateObject("Kixforms.System")
;Code to rebuild forms
|
_________________ Parents were invented to make children happy by giving them something to ignore. |
|
Back to top |
|
 |
benny69 KiXforms Advocate


Joined: 30 Oct 2003 Posts: 567 Location: Lincoln, Ne
|
Posted: Tue Oct 10, 2006 12:23 am Post subject: |
|
|
Its as if the from is hanging onto the file. Gargoyle might have the right idea. _________________ Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta) |
|
Back to top |
|
 |
pvds KiXforms Follower

Joined: 01 Apr 2003 Posts: 19 Location: Netherlands
|
Posted: Tue Oct 10, 2006 11:45 am Post subject: Clear Rectangle |
|
|
I've now tried to use a panel with an picture as Background.
Dispose the picture and it works. Only when you draw a rectangle over it, it doesn't work.
Tried it with the Clear Function to clear the bitmap, but still nothing.
Code: | Break On
$Photo = @SCRIPTDIR + "\Foto\lara.jpg"
$System = CreateObject("Kixforms.System")
$Bitmap = $System.Bitmap($Photo)
$Form = $System.Form
$Form.ClientWidth = 400
$Form.ClientHeight = 600
$Panel1 = $Form.Controls.Add($System.Panel())
$Panel1.Top = 0
$Panel1.Left = 0
$Panel1.Width = 400
$Panel1.Height = 400
$Panel1.BackColor = $System.Color.Green
; $Panel1.BackgroundImage = $Bitmap
$Button1 = $Form.Controls.Add($System.Button())
$Button1.Top = 410
$Button1.Left = 10
$Button1.Text = "Opslaan"
$Button1.Click = "DrawRect()"
$Button1.Width = 150
$Form.Center
$Form.Show
While $Form.Visible
$= Execute($Form.DoEvents)
Loop
Exit 0
Function DrawRect()
$Picture = $System.Graphics.FromImage($Bitmap); Comment these lines and it will work
$Pen = $System.Pen($System.Color.DarkSlateBlue,3); It doesn't work because of
$Picture.DrawRectangle($Pen,20,20,100,100); the DrawRetangle we've tried to use the Clear Function
$Panel1.BackgroundImage = $Bitmap
$Bitmap = $System.Bitmap($Photo);;;;;;;
$Panel1.Refresh()
Sleep 0.5
$ = Delete()
EndFunction
Function Delete()
? @SERROR
$Bitmap.Dispose
Del $Photo
? @SERROR
EndFunction |
|
|
Back to top |
|
 |
benny69 KiXforms Advocate


Joined: 30 Oct 2003 Posts: 567 Location: Lincoln, Ne
|
Posted: Tue Oct 10, 2006 12:52 pm Post subject: |
|
|
maybe this can give you an idea, I use a panel ($SelectPanel) for the selecttion box. _________________ Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta) |
|
Back to top |
|
 |
pvds KiXforms Follower

Joined: 01 Apr 2003 Posts: 19 Location: Netherlands
|
Posted: Tue Oct 10, 2006 6:11 pm Post subject: |
|
|
I was looking at your code already!
Try it tomorrow.
Problem has something to do with "DrawRectangle"
Maybe it is a bug in the framework I have asked Shawn for help maybe he knows?
Thanks,
Peter |
|
Back to top |
|
 |
|