Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Image Locking

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-11-2008, 12:25 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 2,344
Awards Showcase
Forum Contributer 
Total Awards: 1
Default Image Locking

Hi, is there any workaround image locking after being setted to an image control?

I'm developing a database based app, with embeded images as blobs, but to assure the correct image is being selected, i first show it in an image control, and after the user clicks a button I add the image to the database...
If i do not preview the image in the image control all works fine, but if I do preview it, the I cannot add the image to the database, as it is locked...
__________________
Paulo Gomes - Porto, Portugal - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)

My Posts helped you? Consider Buying me a Porto Glass!
Reply With Quote
  #2 (permalink)  
Old 11-11-2008, 03:43 PM
Basic4ppc Veteran
 
Join Date: Jan 2008
Posts: 215
Default work around

Maybe you could copy the image to a temp file before loading it in preview, thus always having the original available
Reply With Quote
  #3 (permalink)  
Old 11-11-2008, 07:16 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 2,344
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

I cannot copy it from within the code as that would, again, lock the file...

@Andrew: I've been searching for a .net solution, and I found some mentions to FileStream.closestream...
Since you are a far better dll maker than me, and have a much greater understnading of how things work in b4ppc and .net, would it be possible to create a "unlock" dll?
__________________
Paulo Gomes - Porto, Portugal - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)

My Posts helped you? Consider Buying me a Porto Glass!
Reply With Quote
  #4 (permalink)  
Old 11-11-2008, 07:39 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,733
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You don't need another dll for that.
You could use a Bitmap object with something like:
Code:
Bitmap.New3(ImageControl.Image)
To create a new copy of the image.
Reply With Quote
  #5 (permalink)  
Old 11-11-2008, 08:11 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 4,463
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

I think that this question is the same as that one:
http://www.basic4ppc.com/forum/bug-r...restarted.html
I hope that all these proposals are only temporary workarounds, because the problem seems beeing a more general one. And I hope that it will be fixed soon, before we turn in circle.

Best regards.
__________________
Klaus
Switzerland

Beginner's Guide / User's Guide
Reply With Quote
  #6 (permalink)  
Old 11-14-2008, 08:33 AM
Junior Member
 
Join Date: May 2007
Posts: 41
Default

Hi, with this code I get the error: "A generic error ocurred in GDI+ continue?"
when I try to save a image that is used in the form control. If I try to continue, not always appears the same error (sometimes yes, sometimes no...)

I think this problem has something to do whith the image locked, is there any solution?

The code:

Sub Globals
Dim Devices(0)
End Sub

Sub App_Start
Form1.Show
AddButton("form1","bSaveimage",2,230,90,20,"Save Image")
AddButton("form1","Button3",100,230,90,20,"To Form")
AddImage("form1","image1",5,5,100,100)

WebCam.New1
Devices() = WebCam.GetAllDevices
WebCam.NewCaptureWindow(0, "image1",1,1,image1.Width,image1.Height)
Webcam.PreviewOn(10)

End Sub


Sub bSaveImage_Click
WebCam.SaveImage(AppPath & "\capture.jpg","J")
End Sub


Sub Button3_Click
bitmap1.New1 (AppPath & "\capture.jpg")
Form1.Image = bitmap1.Value
End Sub

Sub Form1_MouseDown (x,y)
form1.circle(x,y,5,cRed,f)
End Sub
Reply With Quote
  #7 (permalink)  
Old 11-14-2008, 10:48 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

From the .NET docs for Image - "Saving the image to the same file it was constructed from is not allowed and throws an exception." Certainly a Bitmap seems to hold open the file it was created from as you can't delete or rename it in Explorer while the Bitmap exists. I have no idea why this limitation that a Bitmap needs to hold the file open exists but it does seem known/intended as the problem/limitation is documented

I have tried using the Door library to clone the underlying Bitmap and assign the clone to Form1.Image and dispose of Bitmap1 but the original file is still held open! The link to the file seems to follow even a copy of Bitmap1.

This is the only way that I have found to free that link.
Code:
Sub Button3_Click
  bitmap1.New1(AppPath & 
"\capture.jpg")
  Rect1.New1(
00, Bitmap1.Width, Bitmap1.Height)
  Draw.New1(
"Form1"False)
  Draw.DrawImage(Bitmap1.Value, Rect1.Value, Rect1.Value, 
False)
  Form1.Refresh
  Bitmap1.Dispose
End Sub
Note the Bitmap1.Dispose. Even New1ing Bitmap1 to another file or New2ing it to a new size or New3ing it to an image from a different bitmap from a different file or assigning Bitmap1.Value with a different bitmap doesn't break the link between Bitmap1 and the original file. I don't understand this, it is counter-intuitive and I can't think of a reason why this behaviour seems to be designed in to the Bitmap object at a very low level. I'm probably missing something !
Reply With Quote
  #8 (permalink)  
Old 11-14-2008, 01:58 PM
Junior Member
 
Join Date: May 2007
Posts: 41
Smile

Thanks Agraham, I have modified the code in order to be able of use more than once the button3, and works fine! (If not, you get an error when you try to use the bitmap1 object after the dispose sentence)

Sub Globals
Dim Devices(0)
in1=2
End Sub

Sub Button3_Click
AddObject("Bitmap" & in1,"Bitmap")
Control("bitmap" & in1 ,"Bitmap").New1(AppPath & "\capture.jpg")
Rect1.New1(0, 0, Control("bitmap" & in1 ,"Bitmap").Width, Control("bitmap" & in1 ,"Bitmap").Height)
drawer.New1("Form1", False)
Drawer.DrawImage1(Control("bitmap" & in1 ,"Bitmap").Value, Rect1.Value, Rect1.Value,False)
Form1.Refresh
Control("bitmap" & in1 ,"Bitmap").Dispose
End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
can't find a *simple* way to show one transparent image over another image europe Questions (Windows Mobile) 4 11-10-2008 07:44 PM
watermark / transparent image over another image europe Questions (Windows Mobile) 7 11-09-2008 12:55 PM
Locking screen (not to flip when hardware keyboard is openend) corwinckler Questions (Windows Mobile) 5 01-27-2008 04:59 PM
Move an image inside an image control Cableguy Questions (Windows Mobile) 5 05-14-2007 07:40 PM


All times are GMT. The time now is 07:56 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0