C1 Community
ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Creating an overview or thumbnail image

rated by 0 users
This post has 3 Replies | 1 Follower

Top 75 Contributor
Posts 85
Jason10 Posted: Tue, Feb 26 2008 11:35 AM
I would like to create a thumbnail image of the plot without the extras (borders, legend, etc). Just a very compact image that shows only the series, which I guess is the PlotArea. There are numerous image related functions but they all seem to be for exporting the entire chart. Is there an easy way to do this, without changing to chart to minimize all margins? I see the PaintPlotArea event, but I don't think that will help.

--
Jason D.
Senior Software Developer
The Transtec Group, Inc.
Top 25 Contributor
Posts 585
C1_GregL replied on Wed, Apr 9 2008 12:46 PM

A possible solution is to generate an image of the entire chart, and knowing the location and size of the plot area, use bitmap graphics to crop the image.  Here is code to crop the plot area and display it in a Picturebox.

Imports System.Drawing
Imports System.Drawing.Imaging

  1. Dim plotWidth As Integer = C1Chart1.ChartArea.PlotArea.Size.Width
  2. Dim plotHeight As Integer = C1Chart1.ChartArea.PlotArea.Size.Height
  3. Dim offsetX As Integer = C1Chart1.ChartArea.PlotArea.Location.X
  4. Dim offsetY As Integer = C1Chart1.ChartArea.PlotArea.Location.Y
  5. Dim img As Image = C1Chart1.GetImage
  6. Dim bmp As New Bitmap(plotWidth, plotHeight, PixelFormat.Format24bppRgb)
  7. Dim g As Graphics = Graphics.FromImage(bmp)
  8. g.DrawImage(img, New Rectangle(0, 0, plotWidth, plotHeight), offsetX, offsetY, plotWidth, plotHeight, GraphicsUnit.Pixel)
  9. PictureBox1.Image = bmp

To also scale it you can use the code above but just change two lines

'Scale to 50x40 thumbnail
6.  Dim bmp As New Bitmap(50, 40, PixelFormat.Format24bppRgb)
8.  g.DrawImage(img,
New Rectangle(0, 0, 50, 40), offsetX, offsetY, plotWidth, plotHeight, GraphicsUnit.Pixel)

regards,
Greg L

Greg Lutz ComponentOne
Not Ranked
Posts 1
123-123 replied on Tue, May 5 2009 7:41 AM
C1_GregL:
Dim img As Image = C1Chart1.GetImage
Sorry Greg L, but where do you find method "GetImage", namespace C1.WPF.C1Chart? And this sample for WPF?
Top 75 Contributor
Posts 85
Jason10 replied on Fri, May 8 2009 10:00 AM
123-123 wrote:
> *C1_GregL:*
> Dim img As Image = C1Chart1.GetImage
>
> Sorry Greg L, but where do you find method "GetImage", namespace
> C1.WPF.C1Chart? And this sample for WPF?
> ------------------------------------------------------------------------
> http://helpcentral.componentone.com/cs/forums/p/74431/217407.aspx#217407
>

It's a method of the chart, not the namespace, if that's what you're asking. At any rate, I did get the thumbnail created but not without alot of heartache. I did not want to scale since it would look somewhat fuzzy so I shrank the chart first. If you go this route, be aware that the chart does not act well at these small sizes. I can post code if requested, but I would suggest scaling first to see if that fits your needs.

--
Jason D.
Senior Software Developer
The Transtec Group, Inc.
Page 1 of 1 (4 items) | RSS
Contact ComponentOne: 1.800.858.2739 ©1987-2010 ComponentOne LLC All Rights Reserved.