[RESOLVED] Image not fix with imagebox in datareport
I use ADO to access the image from database.I have image display on picturebox.the image fix with picturebox.Code below use to access picture from database.
Code:
Picture2.ScaleMode = vbPixels
Picture2.Cls
Picture2.PaintPicture LoadPicture(Pesttable.Fields("PICTURE")), 0, 0, 150, 150
When I sent the image from picturebox to datareport, Why image not fix with imagebox in datareport?
Code:
Private Sub DataReport_Initialize()
On Error GoTo error
'show the image from database to prit the form
Set Me.Sections("Section1").Controls("Image1").Picture = LoadPicture(Pesttable.Fields("PICTURE"))
error:
End Sub
Re: Image not fix with imagebox in datareport
Re: Image not fix with imagebox in datareport
Anyone know how to fit the image that have large dimension for example 500 X 700 and so on to fit this size in the image in the data report?
Re: Image not fix with imagebox in datareport
Set the Image Control's SizeMode property to either rptSizeStretch or rptSizeZoom.
Code:
Dim oPic As StdPicture
Dim oImgControl As RptImage
Set oPic = LoadPicture(Pesttable.Fields("PICTURE"))
Set oImgControl = DataReport1.Sections("Section1").Controls("Image1")
oImgControl.SizeMode = rptSizeStretch
oImgControl.Width = ScaleX(150, vbPixels, vbTwips)
oImgControl.Height = ScaleY(150, vbPixels, vbTwips)
Set oImgControl.Picture = oPic
Re: Image not fix with imagebox in datareport
Hi, I got the error message "Sub or function not defined.It highlight at yellow color at this word "ScaleX" and "ScaleY" . How I can define it?
Re: Image not fix with imagebox in datareport
ScaleX and ScaleY are methods of the Form, PictureBox, Printer and a few more objects. If this code is running in a module you need to specify a form object.
oImgControl.Width = Form1.ScaleX(150, vbPixels, vbTwips)
oImgControl.Height = Form1.ScaleY(150, vbPixels, vbTwips)
Here is another option to use to convert Pixels to Twips
oImgControl.Width = 150 * Screen.TwipsPerPixelX
Re: Image not fix with imagebox in datareport
Why the image showed in the data report not like same size like original one on my picturebox?The image display in the imagebox in data report, smaller then original one display on the picturebox on the formMenu.Image on picturebox work fine. But image in the imagebox too smaller.Why?. It is something wrong with the scale value?
'show image on form Menu
Code:
Pesttable.Close
Pesttable.Open "Select * from Perosak", conpest, adOpenDynamic, adLockOptimistic
Pesttable.MoveFirst
Text20.Text = Pesttable.Fields("PEST_ID").Value & ""
Text21.Text = Pesttable.Fields("Nama Perosak").Value & ""
Text23.Text = Pesttable.Fields("Nama Sintifik").Value & ""
Text24.Text = Pesttable.Fields("Tanda serangan").Value & ""
'Picture2.Picture = LoadPicture(Pesttable.Fields("PICTURE"))
Picture2.Cls
Picture2.AutoRedraw = True
Picture2.ScaleMode = vbPixels
Picture2.PaintPicture LoadPicture(Pesttable.Fields("Gambar")), 0, 0, 150, 150
'show image in data report
Code:
Dim oPic As StdPicture
Dim oImgControl As RptImage
Set oPic = LoadPicture(Pesttable.Fields("Gambar"))
Set oImgControl = reportperosak.Sections("Section1").Controls("Image1")
oImgControl.SizeMode = rptSizeStretch
oImgControl.Width = frmMenu.ScaleX(150, vbPixels, vbTwips)
oImgControl.Height = frmMenu.ScaleY(15, vbPixels, vbTwips)
Set oImgControl.Picture = oPic
Re: Image not fix with imagebox in datareport
The problem solved.
I forgot to put zero on scale value. Here is the correct one.
Code:
oImgControl.Width = frmMenu.ScaleX(150, vbPixels, vbTwips)
oImgControl.Height = frmMenu.ScaleY(150, vbPixels, vbTwips)
Thank you for helping.