Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Getting ImageButton image from database


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-12-2007, 12:54 PM
Junior Member
 
Join Date: Oct 2007
Location: Berkshire, UK
Posts: 30
Awards Showcase
Beta Tester 
Total Awards: 1
Default Getting ImageButton image from database

Simple question, (sorry if this has already been covered - couldn't find it.) - why does a newly loaded image not show, but is OK if passed to another button?

I have a row of 5 ImageButtons, with no images at the start. They will all shown the same picture: button-1 is loaded from an SQL BLOB and the others are set from the 1st one.

Button-1 does not show the picture, only a red cross. The other 4 buttons show the image correctly.

The code is:-
cmd.CommandText = "SELECT * FROM FileStore WHERE Name = 'camera_pic'"
reader.Value = cmd.ExecuteReader
reader.ReadNextRow
btnPic1.Image = reader.GetImage(2)
reader.Close
btnPic2.Image = btnPic1.Image
btnPic3.Image = btnPic1.Image
btnPic4.Image = btnPic1.Image
btnPic5.Image = btnPic1.Image

Easy workaround is to add "btnPic1.Image = btnPic2.Image" at the end, but why does it not show the first time?

If I replace the first button by an Image control, it shows perfectly. It's no big deal, but curious! Am I doing something wrong?

Geoff.
Reply With Quote
  #2 (permalink)  
Old 11-12-2007, 01:20 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

Does it happen if you don't pass the image to the other controls?
Code:
cmd.CommandText = "SELECT * FROM FileStore WHERE Name = 'camera_pic'" 
reader.Value = cmd.ExecuteReader
reader.ReadNextRow
btnPic1.Image = reader.GetImage(2) 	
reader.Close
Reply With Quote
  #3 (permalink)  
Old 11-13-2007, 10:13 AM
Junior Member
 
Join Date: Oct 2007
Location: Berkshire, UK
Posts: 30
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Yes, button-1 shows as before - just a a red cross (no text either), while of course the other buttons just correctly show the text only.

The other buttons also show as a red cross, if I load them directly.
reader.ReadNextRow
btnPic1.Image = reader.GetImage(2) ' load image into button
btnPic2.Image = reader.GetImage(2) ' load image into button
reader.Close

Interestingly, if I first load into an ImageList control, it makes no difference and buttons still show as a red cross. Whereas if an invisible Image control is used first, everything works fine. Also OK if an Image control is loaded from the ImageList, like this:-
reader.ReadNextRow
ilPMv.Add(reader.GetImage(2)) reader.Close
btnPic1.Image = ilPMv.Item(0) ' no good - red cross
imgTest.Image = ilPMv.Item(0) ' works fine

BTW I'm running 5.80

Geoff.
Reply With Quote
  #4 (permalink)  
Old 11-13-2007, 10:24 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

There is a difference between how images pass in different scenarios.
When you pass an image from one control to another, the image is copied.
When you pass an image from reader.GetImage to a control or an ImageList it is passed by reference (no new image).
I'm not sure why there is a difference between the behavior of Image control and ImageButton control.
Another workaround is:
Code:
btnPic1.Image = reader.GetImage(2) 	' load image into butto
btnPic1.Image = btnPic1.Image
btnPic2.Image = reader.GetImage(2) 	' load image into button
btnPic2.Image = btnPic2.Image
Reply With Quote
  #5 (permalink)  
Old 11-14-2007, 05:37 AM
alfcen's Avatar
Basic4ppc Veteran
 
Join Date: Apr 2007
Location: Okinawa, Ryukyu
Posts: 424
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Hi Geoff,
Please uncheck Transparent for the Image Buttons which reference to an image in a binary file.
Cheers
Robert
Reply With Quote
  #6 (permalink)  
Old 11-16-2007, 08:31 AM
Junior Member
 
Join Date: Oct 2007
Location: Berkshire, UK
Posts: 30
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Thanks Erel and Robert. Very helpful explanation of the behaviour. Unchecking Tranparent does indeed allow the image to display - not something I had thought of and a very useful tip for the future. In this particular example, Transparent is used intentionally so the workaround of re-assigning the image gives an effective result.

Geoff.
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
AddEvent & ImageButton in IDE agraham Bug Reports 1 09-10-2008 09:31 PM
Copy Record from one database to another database. mozaharul Questions & Help Needed 0 07-15-2008 05:47 AM
ImageButton MouseOver superbabicka Questions & Help Needed 0 06-29-2008 09:19 PM
Problem: fetch and store image to/from database willisgt Questions & Help Needed 2 05-13-2008 04:10 PM
How to convert an Access database to a sqlite database Peter Code Samples & Tips 5 07-24-2007 04:20 PM


All times are GMT. The time now is 06:20 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0