Results 1 to 8 of 8

Thread: [RESOLVED] Image not fix with imagebox in datareport

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Image not fix with imagebox in datareport

    Moved to reporting

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    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?

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    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?

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    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

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width