This is a migrated thread and some comments may be shown as answers.

Setting PictureBox in OnItemDataBinding

6 Answers 523 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michael Helm
Top achievements
Rank 1
Michael Helm asked on 29 Aug 2007, 02:15 PM
Hi,
I try to show pictures in the Report Details Section and simply don't bring it to work. I filled a DataSet with some images and gave it as DataSource to the Report.

During the ItemDataBinding event I wand to set the Value Property of my PictureBox:

private
void Detail_ItemDataBound(object sender, System.EventArgs e)
{

    DataSet ds = (DataSet)DataSource;
    System.Drawing.
Bitmap image = 
        (System.Drawing.
Bitmap) ds.Tables["Maps"].Rows[RowIndex]["MapImage"];
    PictureMap.Value = image;
    RowIndex++;
}

As result I get this error:

[ArgumentNullException: Der Wert darf nicht NULL sein.
Parametername: encoder]
 System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) +386727
 System.Drawing.Image.Save(Stream stream, ImageFormat format) +36
 Telerik.Reporting.HtmlRendering.ImageRenderer.SaveImageInStream(HtmlRenderingContext context, Image img, String uniqueImageID, String mimeType) +80
 Telerik.Reporting.HtmlRendering.ImageRenderer.Render(ReportItemBase item, HtmlRenderingContext context) +85
 Telerik.Reporting.HtmlRendering.HtmlItemRender.Telerik.Reporting.HtmlRendering.IReportItemRender.Render(ReportItemBase item, RenderingContext context) +67
 Telerik.Reporting.HtmlRendering.RenderingContext.Render(ReportItemBase item) +47
 Telerik.Reporting.HtmlRendering.Matrix.Render(HtmlRenderingContext context) +1159
 Telerik.Reporting.HtmlRendering.ReportSectionBaseRenderer.Render(ReportItemBase item, HtmlRenderingContext context) +75
 Telerik.Reporting.HtmlRendering.HtmlItemRender.Telerik.Reporting.HtmlRendering.IReportItemRender.Render(ReportItemBase item, RenderingContext context) +67
 Telerik.Reporting.HtmlRendering.RenderingContext.Render(ReportItemBase item) +47
 Telerik.Reporting.HtmlRendering.HtmlPage.RenderBodyInternal(HtmlWriter bodyWriter) +598
 Telerik.Reporting.HtmlRendering.HtmlPage.Render(HtmlTextWriter writer, HtmlRenderingContext renderingContext) +152
 Telerik.Reporting.HtmlRendering.HtmlReport.Render(HtmlTextWriter writer) +353
 Telerik.Reporting.HtmlRendering.HtmlRenderingExtension.Telerik.Reporting.Processing.IRenderingExtension.Render(Report report, Hashtable renderingContext, Hashtable deviceInfo, CreateStream createStreamCallback, EvaluateHeaderFooterExpressions evalHeaderFooterCallback) +260
 Telerik.Reporting.Processing.ReportProcessor.Render(String format, Report reportDefinition, Hashtable deviceInfo, CreateStream createStramCallback) +136
 Telerik.ReportViewer.WebForms.ServerReport.Render(HttpResponse response, String format, Int32 pageNumber, Boolean refresh) +784
 Telerik.ReportViewer.WebForms.ReportPageOperation.PerformOperation(NameValueCollection urlQuery, HttpResponse response) +72
 Telerik.ReportViewer.WebForms.HttpHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) +118
 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +303
 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

Any ideas?

Greetings,
Alexander Brütt

6 Answers, 1 is accepted

Sort by
0
Hrisi
Telerik team
answered on 30 Aug 2007, 03:57 PM
Hello Alexander Brütt,

Thank you for the question.

Our reporting runtime object model is different from the design-time. In all event handlers you should use Telerik.Reporting.Processing namespace objects to accomplish what you want. This approach is represented in the attached project, Report2. Along with it you can find another Report1 with design-time item binding.

Please note that in the Report1's report definition pictureBox1.Value is bound to object of type byte[], in contrast to Report2, where pictureBox.ImageData is bound to an Image object.
 
 
Greetings,
Hrisi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Milton Jurado
Top achievements
Rank 1
answered on 21 Feb 2008, 07:15 PM
Hi Hrisi,
I dont see the attached projects. I am very interested in this solution'

Thanks

Milton
0
Hrisi
Telerik team
answered on 25 Feb 2008, 05:56 PM
Hello Milton,

Thank you for writing.

The project has been removed, because things are a bit different in the latest version Telerik Reporting Q3 2007 SP1. Now the PictureBox is more intelligent and most scenarios work without manual coding. For the value of the PictureBox you can use binary data from the datasource. You can find this approach in our Demos' ProductCatalog example, which comes with the installation of Telerik Reporting (S).

Another strategy is to set the local relative path to the image. This path should be relative to the Report Source code file. Additionally you can use absolute local path. Of course it is possible to use absolute url as well - see our "List Bound Report" example in the Demos.

In the older version discussed with Alexander (released about one year ago) this behavior can be accomplished only by manual codding - typically by handling the ItemDataBound event. The limitation back then was that this worked only at runtime - one could not see the preview in design time.

Please contact us again if this does not answer your question.
 

Greetings,
Hrisi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
rh
Top achievements
Rank 1
answered on 17 May 2008, 09:17 PM
I have reporting Q1 2008 and am still getting the ArgumentNullException for the encoder when setting an image.

My ItemDataBound event is below. _image gets set as an Image through a property in the report. This does seem to only happen after calling Image.GetThumbnailImage so not sure if maybe GetThumbnailImage is stripping out embedded encoding information or something.

private

void detail_ItemDataBound(object sender, System.EventArgs e)

{

if (_image != null)

{

Telerik.Reporting.Processing.

DetailSection section = sender as Telerik.Reporting.Processing.DetailSection;

Telerik.Reporting.Processing.

PictureBox pic = section.Items["pictureBox1"] as Telerik.Reporting.Processing.PictureBox;

pic.Image = _image;

}

}



   at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
   at System.Drawing.Image.Save(Stream stream, ImageFormat format)
   at Telerik.Reporting.Processing.PictureBox.ImageToArray(Image img)
   at Telerik.Reporting.Processing.PictureBox.set_Image(Image value)
   at IMS.Reports.Server.Reports.Avery8160LabelsWithPic.detail_ItemDataBound(Object sender, EventArgs e) in C:\Data\Projects\IMS\Executing\Version 1.7.8.0\Src\IMS\Reports\IMS.Reports\Reports\Avery8160LabelsWithPic.cs:line 42
   at Telerik.Reporting.ReportItemBase.RaiseEvent(Object key, Object sender, EventArgs e)
   at Telerik.Reporting.ReportItemBase.RaiseItemDataBound(Object sender, EventArgs e)
   at Telerik.Reporting.Processing.ReportItemBase.OnItemProcessed()
   at Telerik.Reporting.Processing.ReportItemBase.Process(Object dataItem)
   at Telerik.Reporting.Processing.Report.ProcessDetail(DataRowView dataItem, Int32 level)
   at Telerik.Reporting.Processing.Report.ProcessData(DataView dataView, Int32 level)
   at Telerik.Reporting.Processing.Report.ProcessItem()
   at Telerik.Reporting.Processing.ReportItemBase.Process(Object dataItem)
   at Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Report reportDefinition)
   at Telerik.Reporting.Processing.ReportProcessor.Render(String format, Report report, Hashtable deviceInfo, CreateStream createStramCallback)
   at Telerik.Reporting.Processing.ReportProcessor.Render(String format, Report report, Hashtable deviceInfo, String& mimeType, String& extension, Encoding& encoding)
   at IMS.Reports.Server.Converters.ReportConverter.Convert(ReportResponse reportToConvert, ReportReturnType outputType) in C:\Data\Projects\IMS\Executing\Version 1.7.8.0\Src\IMS\Reports\IMS.Reports\Converters\ReportConverter.cs:line 58
   at IMS.ServiceImplementation.ReportService.ConvertReport(ReportResponse reportToConvert, ReportReturnType outputType) in C:\Data\Projects\IMS\Executing\Version 1.7.8.0\Src\IMS\Services\IMS.ServiceImplementation\ReportService.cs:line 66
   at IMS.ServiceImplementation.ReportService.GetReport(ReportRequest request, ReportReturnType outputType) in C:\Data\Projects\IMS\Executing\Version 1.7.8.0\Src\IMS\Services\IMS.ServiceImplementation\ReportService.cs:line 41
0
Milen
Telerik team
answered on 19 May 2008, 11:08 AM
Hi rh,

When you create a new Image at runtime (and getting thumbnail image does that), the RawFormat of the new image is MemoryBmp. This ImageFormat does not have an encoder that can be used to save the image and this is the reason an exception is thrown.

We consider this behavior as a bug in our system, and that is why from the next release (in a few days) in the described scenario, the image will be saved in a default format (Bmp for example) that has an encoder.

However, as a best practice for the future (and as a workaround for the moment) we advise you to always provide an image in a format that has an encoder to the PictureBox , like Bmp, Png, etc.

Find attached a sample report that shows how to make the thumbnail in the same format as the original image, and thus avoid the issue you are facing.

Let us know if you need further assistance.

Greetings,
Milen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
C
Top achievements
Rank 1
answered on 29 Oct 2010, 03:20 PM
I'm using Q2 2010 and having a similar issue with setting a Picture Box to a runtime generated bitmap. I was able to solve it using the method posted above. When I would set the pictrue boxes image propery to the Bitmap I had created in code, it didn't give an error just displayed all black in the box. Original code was:
Private Sub PictureBox1_ItemDataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.ItemDataBinding
    Dim pb As Processing.PictureBox = sender
    Dim item As Reactor.Options.ProductOptions = pb.DataObject.RawData
    pb.Image = item.BuildOptionSheetImg("DWI_CASEWORK", "Project")
End Sub
Which displayed a black box.

My fixed code in VB using the method above becomes:

Private Sub PictureBox1_ItemDataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.ItemDataBinding
    Dim pb As Processing.PictureBox = sender
    Dim item As Reactor.Options.ProductOptions = pb.DataObject.RawData
    Using Img As Bitmap = item.BuildOptionSheetImg("DWI_CASEWORK", "Project")
        Using ms As System.IO.MemoryStream = New System.IO.MemoryStream
            Img.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
            pb.Image = Bitmap.FromStream(ms)
        End Using
    End Using
End Sub

Which now causes the image to be displayed. Also as a side note, I first tryed ImageFormat.Gif, which thew a GDI+ red box error on the report. ImageFormat.Png seems to work good.
Tags
General Discussions
Asked by
Michael Helm
Top achievements
Rank 1
Answers by
Hrisi
Telerik team
Milton Jurado
Top achievements
Rank 1
rh
Top achievements
Rank 1
Milen
Telerik team
C
Top achievements
Rank 1
Share this question
or