p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Crystal Reports (http://p2p.wrox.com/forumdisplay.php?f=113)
-   -   Picture in crystal report (http://p2p.wrox.com/showthread.php?t=18896)

chen_an September 24th, 2004 05:11 AM

Picture in crystal report
 

Dear all,
I have a field in the database. It uses to store path of picture,
I want to show the picture suit the path in the database

but i don't khow how to do that

anyone help me ?

chen_an

melvik October 7th, 2004 03:22 AM

u just need to select that field(s) from Table & then put that Pic field into ur Report.

Keep in touch.

Always:),
Hovik Melkomian.

chen_an October 8th, 2004 12:17 AM


but i didn't store the picture into database, i only store the path of the picture .... [?]

chen' ;)

chen_an

toekneel October 13th, 2004 09:25 AM

In the report designer, do a right click and select "insert", then choose your object type. From there you will be able to browse to the picture file. Select it to insert it.


RobZ October 25th, 2004 01:34 PM

damn retards, what he is trying to do is tell crystal reports to load an image from a path he is goin to retrieve from a database...

i dont know the answer to that either and i need to do it as well.

can anyone else help us?


chadw November 9th, 2004 04:40 PM

I'm also interested in this solution, got a path to images in database and want to print out the images.

Thanks ... Chad


toekneel November 9th, 2004 05:01 PM

You will not be able to tell Crystal Reports to load an image from a path retrieved in a database. You can, however, place that field into a hyperlink and access it that way.

By the way, RobZ, NOBODY on a forum will want to respond kindly to you when you've called them a "Damn retard." If you intend to get anywhere with forums, treat people with respect and keep those kind of opinions to yourself. I am not a "Damn retard" and I take great offense at your comment.


toekneel November 10th, 2004 12:08 PM

I've just been reviewing Brian Bischoff's excellent book "Crystal Reports .NET Programming". ON pages 370-373 he goes into detail of a workaround on this one. It's too complex to post, and I haven't attempted it. He begins by pointing out that methods in previous versions of Crystal Reports that allowed it aren't available in .NET.

If you haven't found his book, I HIGHLY recommend it:

http://www.crystalreportsbook.com/

I bought my copy at Amazon.com for $28.21, including shipping.



ShadowKnight May 2nd, 2006 10:49 AM

I decided to write this article after realizing how many people have trouble with letting the user upload an image to their crystal report. Say for an example if the user wants to change or upload their logo onto the crystal report. How can you do this? How the developers can provide this facility to the users?

We all know that users cannot customize crystal reports much. Once the crystal report is generated, users don't have much of a choice to change the fields as they wish. This article is going to demonstrate how can the user upload or change an image on the crystal report.

This is actually a very simple example. Even if you have a novice knowledge about Crystal reports you will be able to understand how this works. I am using Crystal reports 11 for this demonstration.

To start off from the beginning, create a new windows application and add a crystal report viewer and a browse button.

This browse button will allow the user to add an image to the report. Add a crystal report into your project.

Report Schema:

We all know that we need to provide a schema for the crystal repot. Here is an XML view of the report schema that we are going to supply for the report.

<?xml version="1.0" standalone="yes"?>
          <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-
          microsoft-com:xml-msdata">
                  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="en-AU">
                       <xs:complexType>
                           <xs:choice maxOccurs="unbounded">
                              <xs:element name="Images">
                                  <xs:complexType>
                                       <xs:sequence>
                                           <xs:element name="path" type="xs:string" minOccurs="0" />
                                           <xs:element name="image" type="xs:base64Binary" minOccurs="0" />
                                       </xs:sequence>
                                  </xs:complexType>
                              </xs:element>
                           </xs:choice>
                       </xs:complexType>
                  </xs:element>
          </xs:schema>

BLOB field:

In order to add an image to the crystal report (considering the image field is coming from the database) we need to have a BLOB field in the schema. When you want to store images, documents or different custom types in the database you use a BLOB field. BLOB stands for Binary Large Object.

<xs:element name="path" type="xs:string" minOccurs="0" />
<xs:element name="image" type="xs:base64Binary" minOccurs="0" />

If you inspect this schema we can see that we have a table called "Images" and two columns "path" and "image". "image" column is type Base64 Binary. This is our BLOB field.What we are going to do in our program is when the user selects the image to upload we store that image in a BLOB field as a stream of bytes and then supply that dataset to the report.

CreateTable() method will illustrate how to generate this schema in the program.

Generating the schema for the report:

There are other ways you can create the schema but this will give you a clearer idea about the column fields.

Creating the table:

private void CreateTable()

{

          //create a new data set.

          this.DsImages = new DataSet();

          //create a new table with two columns and add the table to the
      dataset

DataTable ImageTable = new DataTable("Images");

          //in here the "path" column is not really needed. Image column is
      just enough.

ImageTable.Columns.Add(new DataColumn("path",typeof(string)));

          //Important note

          //Note the type of the image column. You want to give this column
      as a blob field to the crystal report.

          //therefore define the column type as System.Byte[]

          ImageTable.Columns.Add(new DataColumn("image",typeof(System.Byte[])));

          this.DsImages.Tables.Add(ImageTable);

}

If you notice the "image" column you can see that the type of that column is System.Byte[]. This is pretty straight forward. Just create a table with two columns. Then add it to the dataset. Now you can create the schema using this line:

this.DsImages.WriteXmlSchema(@"c:\temp\ImagesSchem a.xsd");

Once we have the schema ready we can provide it to the crystal report.




In the field explorer we can see Images table and the two columns path and image. When you drag the image column onto the report you can see the type of that field is IBlobFieldObject. These fields will read a stream of bytes and convert it back to an image. So our task is pretty much done. The code below shows you how it can save the image as a stream of bytes in the BLOB field.

private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)

{

          try

          {

                   //get the image file into a stream reader.

                   FileStream FilStr = new FileStream(this.openFileDialog1.FileName, FileMode.Open);

                    BinaryReader BinRed = new BinaryReader(FilStr);

                   //Adding the values to the columns

                   // adding the image path to the path column

                   DataRow dr = this.DsImages.Tables["images"].NewRow();

                   dr["path"] = this.openFileDialog1.FileName;

                   //Important:

                   // Here you use ReadBytes method to add a byte array of the image stream.

                   //so the image column will hold a byte array.

                   dr["image"] = BinRed.ReadBytes((int)BinRed.BaseStream.Length);

                   this.DsImages.Tables["images"].Rows.Add(dr);

                   FilStr.Close();

                   BinRed.Close();

                   //create the report object

                   DynamicImageExample DyImg = new DynamicImageExample();

                   // feed the dataset to the report.

                   DyImg.SetDataSource(this.DsImages);

                   this.crystalReportViewer1.ReportSource = DyImg;

          }

          catch(Exception er)

          {

                   MessageBox.Show(er.Message,"Error");

          }

}

You write this in the FileOk method of the openFileDialog. You use the BinaryReader.ReadBytes method to read the byte array.

dr["image"] = BinRed.ReadBytes((int)BinRed.BaseStream.Length);

If you inspect this line of code you can see that we have assigned a byte array in the "image" column of the table. This byte array is the image that the user selected. So when you supply this dataset to the crystal report the IBlobFieldObject in the report will convert this byte array back to the image.

That is all you need to understand in this program. Below I have listed all the important steps you need to understand.

    * User selects an image.
    * We save the image in a blob field as a stream of bytes.
    * Supply the dataset to the report which contains the BLOB field.
    * Report will convert the stream of bytes back to the image and show it.

Conclusion:

Using this example in we can give the user to customize the images they want to upload to the report. This would be a good implementation in situations like if the users want to change the images on the report or upload their logos by them selves. Users don't have to contact their software development team every time they want to change an image on the report. Customizing the crystal report at the user end is not possible when it comes to moving the fields across the report or adding new fields. This article only helps you to understand how you can upload an image at run time. It does not tell how you can customize a crystal report at runtime. I hope you understood the concept of this article.

Just download this program and try it. Make sure you have Crystal Reports 11. The code I have written here is basic. You shouldn't have any problems understanding this.


prat_0510 May 22nd, 2006 03:41 AM

 I m generating Barcode image which i want on my crystal report...
This is my code ......

 Dim ds As New dsProductTag
        Dim rpt As New rptProdTag

        Dim bc As C1BarCode

        Me.SqlConnection1.ConnectionString = System.Configuration.ConfigurationSettings.AppSett ings("sqlConnString")
        Me.SqlConnection1.Open()

        Me.SqlSelectCommand1.CommandText = "SELECT * FROM PRMAProductUPCDetail where VarProductId='1'"
        Me.SqlSelectCommand1.Connection = Me.SqlConnection1

        Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1

        Me.SqlDataAdapter1.Fill(ds)

        For Each dr As DataRow In ds.Tables(0).Rows
            bc = New C1BarCode
            bc.CodeType = CodeTypeEnum.Ean13
            bc.Text = CStr(dr("VarUPC"))
            bc.ShowText = True

            dr("ImgProductTag") = bc.Image
        Next

          rpt.SetDataSource(ds)
        CrystalReportViewer1.ReportSource = rpt

        Me.SqlConnection1.Close()

 i already have image column in my dataset table
i ve drag the image field on the report n its showing BLOB type but on execution it is not shoiwing the image only its space cross image..
can any one help me...
what i m missing.



All times are GMT -4. The time now is 04:04 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.