|
|
Sharpen Graph
Last post 05-29-2008, 4:27 AM by roger. 14 replies.
-
05-15-2008, 1:50 AM |
-
elf9210
-
-
-
Joined on 04-18-2006
-
-
Posts 158
-
-
-
-
|
Sharpen Graph
Attachment: Present (inaccessible)
Hi Aspose.Chart Team,
Currently, I have a problem sharpening a graph by using Aspose.Chart API.
I am building a pdf conversion process by using the latest version of Aspose.Word and Aspose.Pdf APIs.
and while building the word document template, I am importing a BarCode image (using Aspose.BarCode) and a Graph image (using Aspose.Chart). I am using MailMerge to import those image.
(I have attached the example Word document file)
When I converted the Word document into a Pdf file (by using Aspose.Pdf), the Graph image looks like in low quality but the BarCode image is in good quality.
(I have attached the example pdf file)
I have tried to print the pdf file to my printer, and the BarCode image looks really sharp and the Graph image looks a little bit blurry.
Is there anyway to sharpening the Graph image?
And this is my code to generate the Graph image:
Dim chart As Chart = New Chart()
Dim s As Series = New Series()
s.ChartType = ChartType.Bar s.CustomAttributes.BarWidth = 5
s.DefaultDataPoint.Color = System.Drawing.Color.FromArgb(255, 0, 0, 0) s.DataPoints.Add(1, 4) s.DataPoints.Add(2, 0) s.DataPoints.Add(3, 8) s.DataPoints.Add(4, 2) s.DataPoints.Add(5, 1) s.DataPoints.Add(6, 7.2) s.DataPoints.Add(7, 1) s.DataPoints.Add(8, 6) s.DataPoints.Add(9, 4.5) s.DataPoints.Add(10, 2.5) s.DataPoints.Add(11, 0.6) s.DataPoints.Add(12, 32) s.DataPoints.Add(13, 3.8) s.DataPoints.Add(14, 4) s.DataPoints.Add(15, 0) s.DataPoints.Add(16, 1) s.DataPoints.Add(17, 0) s.DataPoints.Add(18, 0) s.DataPoints.Add(19, 1) s.DataPoints.Add(20, 0) s.DataPoints.Add(21, 3) s.DataPoints.Add(22, 0) s.DataPoints.Add(23, 2.7) s.DataPoints.Add(24, 1.9) s.DataPoints.Add(25, 22) s.DataPoints.Add(26, 3) s.DataPoints.Add(27, 3.6) s.DataPoints.Add(28, 4.9) s.DataPoints.Add(29, 28) s.DataPoints.Add(30, 16) s.DataPoints.Add(31, 11.6)
chart.ChartArea.AxisX.IsMajorGridVisible = False chart.ChartArea.AxisY2.IsVisible = False
chart.ChartArea.AxisY.DefaultLabel.Font = New System.Drawing.Font("Arial", 6) chart.ChartArea.AxisX.DefaultLabel.Font = New System.Drawing.Font("Arial", 6) chart.ChartArea.AxisX.Title.Font = New System.Drawing.Font("Arial", 8) chart.ChartArea.AxisY.Title.Font = New System.Drawing.Font("Arial", 8) chart.ChartArea.AxisX.Title.Text = "Hours of The Day" chart.ChartArea.AxisY.Title.Text = "No of Calls"
chart.ChartArea.AxisX.IsAutoCalc = False chart.ChartArea.AxisX.Interval = 2 chart.ChartArea.AxisX.Minimum = 0 chart.ChartArea.AxisX.Maximum = 31 chart.ChartArea.AxisX.IntervalType = IntervalType.Int
chart.ChartArea.AxisY.MinorTickMark.IsVisible = False
chart.ChartArea.Margin = 4 chart.ChartArea.MarginRight = 20
chart.ChartArea.MarginLeft = 5 chart.ChartArea.MarginTop = 10 chart.ChartArea.MarginBottom = 2
chart.ChartArea.AxisX.Point2Offset = New PointF(15, 0)
chart.ChartArea.Transparence = 255 chart.BackColor = System.Drawing.Color.FromArgb(255, 255, 255) chart.ChartArea().BackColor = System.Drawing.Color.FromArgb(255, 255, 255) chart.ChartArea.AxisX.Color = System.Drawing.Color.Black chart.ChartArea.AxisY.Color = System.Drawing.Color.Black
chart.ChartArea.AxisX.MajorTickMark.Length = 0
chart.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality chart.ChartArea.LegendBox.IsVisible = False
chart.SeriesCollection.Add(s)
chart.Height = 184 chart.Width = 325
Dim chartBitmap As Bitmap = chart.GetChartImage()
Thank You.
Regards,
Jarry
|
|
-
05-15-2008, 2:29 AM |
-
Amjad Sahi
-
-
-
Joined on 08-30-2006
-
-
Posts 5,104
-
-
-
-
|
Hi Jarry,
Well chart.GetChartImage().... will get you a .bmp format object. I think your can try to get an EMF format chart using Chart.Save(MemoryStream stream, System.Drawing.Imaging.ImageFormat) method and insert the image as a stream using builder object into MS.Word document if the image quality is enhanced.
Thanks
Amjad Sahi Support Developer, Aspose Nanjing Team Contact Us
|
|
-
05-15-2008, 6:40 PM |
-
elf9210
-
-
-
Joined on 04-18-2006
-
-
Posts 158
-
-
-
-
|
Re: Sharpen Graph
Attachment: Present (inaccessible)
Thanks Amjad.
I have tried to use the stream method,
Dim v_image_stream As System.IO.MemoryStream = New System.IO.MemoryStream chart.Save(v_image_stream, System.Drawing.Imaging.ImageFormat.Emf)
builder.InsertImage(v_image_stream)
and the Graph chart image in the WordDoc and PDF file is still blur.
(i have attached the result)
just wondering, if there's another way to make the Graph image sharper, or probably another Aspose.Chart properties that i need to enable/disable?
(ps: please look at the BarCode image, I used the same method in Aspose.Word builder to insert the image, and the BarCode image quality is sharper)
Thank you very much Amjad.
Regards,
Jarry
|
|
-
05-15-2008, 10:46 PM |
-
roger
-
-
-
Joined on 11-24-2005
-
-
Posts 178
-
-
-
-
|
Hi Jarry,
If graph created using Aspose.Charts independently is fine, I think blur issue was caused by the graph being changed size when it was inserted into other document (pdf or word). So we suggest that create a vector format(.emf) chart to insert into other document.
I consider the issue by following steps.
- Is the .emf graph created by ? Aspose.Charts API fine? If yes, Aspose.Charts is no problem.
- Inserting it into Ms.Word is Okay? Opens the word file, changes the word to different zoom view, you can see whether it is fine.
- If step 2 is okay, converts word to pdf. If can not get a satisfying result, I think that may be caused by Aspose.Wors. I am not very familiar with Aspose.Words API. For your issue, you can put in Aspose.Words for .NET, Java and Reporting Services forum. At the same time, Could you attach your code here about inserting into ms.word and converting ms.word to pdf?
Roger Mo Developer Aspose Nanjing Team Contact Us
|
|
-
05-16-2008, 12:25 AM |
-
elf9210
-
-
-
Joined on 04-18-2006
-
-
Posts 158
-
-
-
-
|
Re: Sharpen Graph
Attachment: Present (inaccessible)
Hi Roger,
I have attached my example project (vb.net - Visual Studio 2005).
In the testing project, click on the 1st button first to manipulate the word document (i.e. inserting the BarCode image and the GraphChart image by using bookmarks). then click on the 2nd button to convert the manipulated worddoc file into pdf file.
Regarding your questions:
- The .emf graph is successfully created, and I agree Aspose.Chart is working great.
- When inserted into the Word document, the Graph Chart image is blury (but not BarCode image)
- I cannot log to Aspose.Word forum because the BarCode image is in good quality but not Aspose.Chart, where the both codes are doing similar process.
Please refer to the code that I have attached, and please refer to the BarCode generation code. There's nothing special in the BarCode generation code and the barcode image is in good quality when the document is converted to the pdf file.
I am just wondering if i missed some Aspose.Chart properties to make the graph in good quality.
Thank you very much Roger for your helps again. I am sorry to be a pain :)
Regards,
Jarry
|
|
-
05-16-2008, 2:34 AM |
-
roger
-
-
-
Joined on 11-24-2005
-
-
Posts 178
-
-
-
-
|
Re: Sharpen Graph
Attachment: Present (inaccessible)
Hi Jarry,
You have set the graph quality property. The graph is very fine and don't need to do anything again.
I think the problem is caused by the bookmark in test_bookmark.doc being too smaller and this makes the graph lees. Regardless of Aspose.Charts, inserts a big picture to ms.word in a smaller range, usually the picture becomes fuzzy. The BarCode image is smaller than the bookmark, so it looks finely.
I chage ms.word's zoom and save to several file. The quality of Aspose.Charts image is not effected in big zoom.
Roger Mo Developer Aspose Nanjing Team Contact Us
|
|
-
05-18-2008, 6:05 PM |
-
elf9210
-
-
-
Joined on 04-18-2006
-
-
Posts 158
-
-
-
-
|
Re: Sharpen Graph
Attachment: Present (inaccessible)
Thank you Roger,
Have you tried to convert the word doc to pdf by using the project that I gave you? the BarCode decrease the size to smaller image.
If you convert the word doc to a pdf file, you can see that the BarCode quality stays in good quality (no fuzzy) and the GraphChart picture becomes fuzzy. (ps: the BarCode picture and its bar line are smaller compared to the GraphChart picture).
To compare picture quality bertween GraphChart and BarCode, I converted the word doc to pdf and print them to a paper. I can see the GraphChart Bar has fuzzy line at the side of the Bar, and the BarCode image has no fuzzy line at the bar (and the BarCode bar line is thiner compared to the GraphChart bar line).
I have attached the example pdf file (result2.pdf), and please print them to compare the Bar quality between them.
I am not sure what Aspose.BarCode team use for their picture generation, but the BarCode result is really sharp in small picture as well (please refer to the pdf file).
Best Regards,
Jarry
|
|
-
05-18-2008, 10:07 PM |
-
roger
-
-
-
Joined on 11-24-2005
-
-
Posts 178
-
-
-
-
|
Re: Sharpen Graph
Attachment: Present (inaccessible)
Hi Jarry,
Please check the atttached project. I have increased the size of chart bookmark.
Roger Mo Developer Aspose Nanjing Team Contact Us
|
|
-
05-19-2008, 6:36 PM |
-
elf9210
-
-
-
Joined on 04-18-2006
-
-
Posts 158
-
-
-
-
|
Thank you very much Roger,
Again, It works Perfectly! and I would like to thank you to provide me with the sample codes and I would like to apology regarding the WordDoc issue.
You are right, there's a problem with the newer version of Aspose.Word Api (ver 5.1.0.0), and now by using this sample codes, I can create an Aspose.Word forum regarding this newer Aspose.word version issue.
Once again, thank you very much for your helps and supports Roger.
Best Regards,
Jarry
|
|
-
05-20-2008, 7:41 PM |
-
elf9210
-
-
-
Joined on 04-18-2006
-
-
Posts 158
-
-
-
-
|
Hi Roger,
This is the response from Aspose.Word team,
The graph chart is a metafile with resolution set to 133 DPI. Since version 4.4.3.0 logic has changed. Aspose.Words in the current implementation always converts metafiles to PNG on PDF export. You can see the image file in the same directory with main XML if you export to Aspose.Pdf XML format. Resulting raster image quality is dependent on the output resolution.
1. If resolution is not specified in the image itself then output resolution is taken from the following property:
doc. SaveOptions.PdfExportMetafileResolution
2. If resolution is specified as in your case then the minimum of these two values is taken.
We don’t see the reason to scale images with higher resolution than specified in the file and what is intended for them. This behavior is by design. You can remove resolution properties from the metafile before you insert it to the document. If both vertical and horizontal resolution are zeroes you can easily control quality by increasing PdfExportMetafileResolution property. Default is 300 DPI. This should be enough in most cases.
Another way is converting metafiles to raster externally, before you insert the images.
I expect one reasonable question. That’s great but you can ask why MS Word renders the metafile without blur effect. Most probably it completely ignores image resolution and uses some default. But we give the possibility to control resolution of individual images.
Forum: http://www.aspose.com/community/forums/127924/image-issue-in-version-5.2.0.0/showthread.aspx#127924
My question is, how do we increase the metafile resolution DPI for the chart image?
I have tried this syntax "chart.SetResolution(200, 200)" after setting up the chart width and height, but it didn't do anything. the image is still in 133 DPI.
Regards,
Jarry
|
|
-
05-21-2008, 2:13 AM |
-
roger
-
-
-
Joined on 11-24-2005
-
-
Posts 178
-
-
-
-
|
Hi Jarry,
I try to change the metafile resolution dpi. But i don't find successful way to do that. I think the metafile resolution can not be set.
Aspose.Chart.Chart.SetResolution(float xDpi, float yDpiY) applies only to .bmp, .gif, .jpg, .jpeg, .tiff. We made a mistake that the method is in defect of correct remarks.
Please try the following code:
chart.SetResolution(300, 300)
builder.MoveToBookmark("CHARTHERE")
' convert chart to image stream object Dim v_image_stream As System.IO.MemoryStream = New System.IO.MemoryStream
' or jpeg, png, gif, tiff chart.Save(v_image_stream, System.Drawing.Imaging.ImageFormat.bmp)
builder.InsertImage(v_image_stream)
Roger Mo Developer Aspose Nanjing Team Contact Us
|
|
-
05-21-2008, 8:37 PM |
-
elf9210
-
-
-
Joined on 04-18-2006
-
-
Posts 158
-
-
-
-
|
Hi Roger,
I have tried the above codes and the picture still blured.
However, I have tried the codes from Aspose.Words and it works now, the Chart picture display in high quality.
This is the sample code from Aspose.Word:
Image srcImage = Image.FromFile("chart.emf");
Bitmap dstImage = new Bitmap(newWidth, newHeight, newFormat);
dstImage.SetResolution(newResolution, newResolution);
using (Graphics gr = Graphics.FromImage(dstImage))
gr.DrawImage(srcImage, 0, 0, dstImage.Width, dstImage.Height);
dstImage.Save("chart.png", ImageFormat.Png);
Forum: http://www.aspose.com/community/forums/128155/image-issue-in-version-5.2.0.0/showthread.aspx#128155
probably this feature can be implemented to Aspose.Chart (i.e. gives the bitmap with high resolution from the emf format) :)
Once again, Thank you very much Roger for all your helps and supports.
Best regards,
Jarry
|
|
-
05-22-2008, 4:34 AM |
-
roger
-
-
-
Joined on 11-24-2005
-
-
Posts 178
-
-
-
-
|
Hi Jarry,
Thanks for your suggestion!
We will look into it and provide this featrue soon.
Roger Mo Developer Aspose Nanjing Team Contact Us
|
|
-
05-22-2008, 5:48 PM |
-
05-29-2008, 4:27 AM |
-
roger
-
-
-
Joined on 11-24-2005
-
-
Posts 178
-
-
-
-
|
Re: Sharpen Graph
Attachment: Present (inaccessible)
Hi Jarry,
Please test the setting resolution feature using attached version.
We added 4 public methods. There are:
public void SetResolution(string imageFile, float xDpi, float yDpiY)
public void SetResolution(string imageFile, float xDpi, float yDpiY, int width, int height, PixelFormat pixelFormat)
public void SetResolution(Stream stream, ImageFormat imageFormat, float xDpi, float yDpiY)
public void SetResolution(Stream stream,ImageFormat imageFormat, float xDpi, float yDpiY, int width, int height, PixelFormat pixelFormat)
Roger Mo Developer Aspose Nanjing Team Contact Us
|
|
|
|