cancel
Showing results for 
Search instead for 
Did you mean: 

Change Picture in CR

Former Member
0 Kudos
96

Hi:

I have a picture inserted in my report...Now I want change this picture throught code(VB6)...Wich way i can do this?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Manuel,

please find a VB6 sample [here|ftp://ftp.businessobjects.com/pub/incoming/changeimages_998900.zip].

Falk

Former Member
0 Kudos

Hi Falk:

Thanks for the project...That's all I need..

One question...Do you have try with more than one picture?

PS:Next time I post the question in the correct forum...sory

Thanks

Former Member
0 Kudos

Hi:

Sory but this line:

Set pic1.FormattedPicture = LoadPicture(App.Path + "\azul.jpeg")

the CR only accept .bmp files????

former_member208657
Active Contributor
0 Kudos

Keep in mind that the Crystal Reports designer permits you to change images with Crystal Reports XI R1, R2 and 2008 now by using a formula in your report. If you right click and format your picture object in the Crystal Reports designer you can change the Graphic location formula to select a picture on a mapped drive, UNC path, or HTTP path. This is a good way to design your report because it works the same way in the designer as it would in the application. Less code to write

Note: Crystal Reports 2008 does not ship with the RDC. The last version where the RDC was available is XI R2.

Edited by: David Hilton on Aug 12, 2008 8:35 AM

Former Member
0 Kudos

Hi David:

In fact a good tip,but can you help me a little more?Is in the Hiperlink (File)section that a can write the formula?

And you know a code that accept all kind of extensions .bmp,.jpeg,.jpg etc etc,no put in the formula?

Thanks

Former Member
0 Kudos

Hello Manuel,

pelase see code for a similar samples below.

This sample uses a JPG.

Hope this helps

Falk

---------------------------------

VERSION 5.00
Object = "{8767A745-088E-4CA6-8594-073D6D2DE57A}#9.2#0"; "crviewer.dll"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   6690
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   10335
   LinkTopic       =   "Form1"
   ScaleHeight     =   6690
   ScaleWidth      =   10335
   StartUpPosition =   3  'Windows Default
   Begin CRVIEWER9LibCtl.CRViewer9 CRViewer
      Height          =   6015
      Left            =   360
      TabIndex        =   0
      Top             =   360
      Width           =   9615
      lastProp        =   500
      _cx             =   16960
      _cy             =   10610
      DisplayGroupTree=   -1  'True
      DisplayToolbar  =   -1  'True
      EnableGroupTree =   -1  'True
      EnableNavigationControls=   -1  'True
      EnableStopButton=   -1  'True
      EnablePrintButton=   -1  'True
      EnableZoomControl=   -1  'True
      EnableCloseButton=   -1  'True
      EnableProgressControl=   -1  'True
      EnableSearchControl=   -1  'True
      EnableRefreshButton=   -1  'True
      EnableDrillDown =   -1  'True
      EnableAnimationControl=   -1  'True
      EnableSelectExpertButton=   0   'False
      EnableToolbar   =   -1  'True
      DisplayBorder   =   -1  'True
      DisplayTabs     =   -1  'True
      DisplayBackgroundEdge=   -1  'True
      SelectionFormula=   ""
      EnablePopupMenu =   -1  'True
      EnableExportButton=   0   'False
      EnableSearchExpertButton=   0   'False
      EnableHelpButton=   0   'False
      LaunchHTTPHyperlinksInNewBrowser=   -1  'True
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

' If the jpg only displays as generic icon, check
' <a href="http://support.crystaldecisions.com/library/kbase/articles/c2007340.asp" TARGET="test_blank">http://support.crystaldecisions.com/library/kbase/articles/c2007340.asp</a>
'
' MS Photo Editor can be downloaded from
' <a href="http://www.megaiq.com/downloads.htm" TARGET="test_blank">http://www.megaiq.com/downloads.htm</a>

Option Explicit
  
Dim CrApplication As CRAXDRT.Application
Dim WithEvents crReport As CRAXDRT.Report
Attribute crReport.VB_VarHelpID = -1
Dim WithEvents crSection As CRAXDRT.Section
Attribute crSection.VB_VarHelpID = -1

Private Type JPEGINFO
    Width             As Long
    Height            As Long
End Type

Private Function GetJPGInfo(ByVal FileName As String) As JPEGINFO
    Dim bChar As Byte
    Dim a As Byte, b As Byte
    Dim c As Byte, D As Byte
    Dim E As Byte, f As Byte
    Dim i As Integer
    Dim DotPos As Integer
    Dim Header As String
    Dim blExit As Boolean
    Dim MarkerLen As Long
    Dim ImgWidth As Integer
    Dim ImgHeight As Integer
    Dim ImgSize As String
    Dim fnum As Integer
    Dim ImageInfo As JPEGINFO
    On Error Resume Next

    fnum = FreeFile
    Open FileName For Binary As #fnum

    ImgSize = LOF(fnum) / 1024
    DotPos = InStr(ImgSize, ",")
    ImgSize = Left(ImgSize, DotPos)

    Get #fnum, , bChar
    Header = Hex$(bChar)
    Get #fnum, , bChar
    Header = Header & Hex$(bChar)
    If Header <> "FFD8" Then Exit Function

    While Not blExit
        Do Until Hex$(bChar) = "FF"
            Get #fnum, , bChar
        Loop

        Get #fnum, , bChar
        If Hex$(bChar) >= "C0" And _
                Hex$(bChar) <= "C3" Then
            Get #fnum, , bChar
            Get #fnum, , bChar
            Get #fnum, , bChar

            Get #fnum, , bChar
            a = bChar
            Get #fnum, , bChar
            b = bChar
            Get #fnum, , bChar
            c = bChar
            Get #fnum, , bChar
            D = bChar

            ImgHeight = CInt(a * 256 + b)
            ImgWidth = CInt(c * 256 + D)
            blExit = True
        Else
            If Hex$(bChar) = "DA" Then
                blExit = True
            Else
                Get #fnum, , bChar
                E = bChar
                Get #fnum, , bChar
                f = bChar
                MarkerLen = (E * 256 + f) - 2

                Dim marker As String
                marker = String(MarkerLen, vbNullChar)
                Get #fnum, , marker
            End If
        End If
    Wend

    Close #fnum

    With ImageInfo
        .Width = ImgWidth
        .Height = ImgHeight
    End With

    GetJPGInfo = ImageInfo
End Function

Private Sub Form_Load()
 Set CrApplication = New CRAXDRT.Application
 Set crReport = CrApplication.OpenReport(App.Path & "\Logos.rpt")
 Set crSection = crReport.Sections.Item("D")
 
 CRViewer91.ReportSource = crReport
 CRViewer91.ViewReport
End Sub

Private Sub crSection_format(ByVal pFormattingInfo As Object)
 Dim sImagePath As String
 Dim iHeightTwips As Integer
 Dim iWidthTwips As Integer
 
 'Retrieve the path of the image
 sImagePath = App.Path & crSection.ReportObjects.Item("Feld3").Value
 'sImagePath = App.Path & "\cd.jpg"
    
 'Set the location of the OLE Object to path of the image
 Dim crOleObject As CRAXDRT.OLEObject
 Set crOleObject = crSection.ReportObjects.Item("Bild1")
 crOleObject.SetOleLocation sImagePath
 
 'Retrieve the file information from the file header
 Dim InfoHeader As JPEGINFO
 InfoHeader = GetJPGInfo(sImagePath)
  
 'Convert the image height / width from pixels to twips
 iHeightTwips = InfoHeader.Width * Screen.TwipsPerPixelX
 iWidthTwips = InfoHeader.Height * Screen.TwipsPerPixelY
 crOleObject.Width = iHeightTwips
 crOleObject.Height = iWidthTwips
End Sub

Private Sub Form_Resize()
 CRViewer.Left = 0
 CRViewer.Top = 0
 CRViewer.Width = ScaleWidth
 CRViewer.Height = ScaleHeight
End Sub

Former Member
0 Kudos

Hi Falk:

Thanks for the code,but I got a few errors in a some lines...

Can you put this code in a project?

This is only for JPG right?...and for the others extensions?.GIF .JPEG etc etc?

Thanks

former_member208657
Active Contributor
0 Kudos

Crystal Reports supports the following image formats.

- .jpg

- .bmp

- .png

- .tiff

It does not support .gif format.

Former Member
0 Kudos

Hi David:

In fact you are right...I had try with different formats and work very well...

Thanks to you and Falk to the code...

Edited by: Manuel Sacramento on Aug 10, 2008 11:08 PM

Answers (1)

Answers (1)

former_member183750
Active Contributor
0 Kudos

Also Manuel, just for consistency, post your VB 6 queries to the legacy forum:

This forum is for .NET queries only.

Thank you for your understanding,

Ludek