specifying the dimensions of output image file

Q&A for C, C++, and/or C# developers using DPlot

Moderator: DPlotAdmin

Post Reply
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

specifying the dimensions of output image file

Post by rkm »

In one application I'm creating a plot and writing it to an image file from which it can be loaded by another application. I want to specify the dimensions in pixels of the output image file to be certain it will fit comfortably in a specified window size in the second application.

There must be someplace I can specify the image dimensions but I seem to be missing it. Any help would be appreciated.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

[SetPluginImageDims(wPixels,hPixels|,option1|,option2|,option3|,option4||||)]

Online: http://www.dplot.com/help/index.htm?set ... ommand.htm
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

I failed to mention I need to do this from DPlot Jr.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

The documentation is incorrect. This command is available with DPlot Jr (but not Viewer).
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

Thanks for the prompt reply.

I tried the function but it does not seem to be performing as I expected:

I started by sending the DPlot_Command to set the image dimensions
[SetPluginImageDims(475,525,24)]

followed by a [FileSaveAs(...) command

The file was saved but the image dimensions were: 577,436.

I then tried changing the specified dimensions but no matter what values I set there was no change in the plot image dimensions for PNG files. I have not tried it with other file types.

-rob
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

The only thing I can think of off the top of my head is the resolution is set to some value > 100 dpi. If you use [SetPluginImageDims(475,525,24,0,0)] then you might get better results.

If you've used a Size command and don't want white space to be cropped, you'll also want to use [SetImageCrop(0)] before the FileSaveAs.

If none of this helps, please send me a saved DPlot file that you're having trouble with.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

I tried [SetPluginImageDims(475,525,24,0,0)] -it made no difference.

There's no saved DPlot file, I'm using DPlot Jr. and DDE

Am I correct in assuming that the SetPluginImageDims() should come after the DPLOT_PLOT(...) command?

Other than the dimensions issue the image is being saved properly.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

There's no saved DPlot file, I'm using DPlot Jr. and DDE
Understood, but you can still save the graph as a DPlot file, either manually in DPlot Jr or with DPlot_Command(doc,"[FileSaveAs(1,""filename.grf"")]");
Am I correct in assuming that the SetPluginImageDims() should come after the DPLOT_PLOT(...) command?
Yes.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

OK I'll email you a grf and a png, of the same image, supposed to be 475x525.

In addition to the dimensions problem with the png you can see that some of the vertical lines, that appear correctly in the grf, have been left out of the png.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

I don't know. Your PNG file was corrupt so I couldn't look at it, but that's probably a smaller issue. I opened your file in DPlot and ran this macro:

SetPluginImageDims(475,525,24)
FileSaveAs("Portable Network Graphics","test.png")

and I get a 475x525 PNG. Thinking this might be something odd about DPlot Jr only, I modified the C test program to include this line after the call to dPlot_Plot:

dPlot_Command(DocNum,"[SetPluginImageDims(475,525,24)][FileSaveAs(\"Portable Network Graphics\",\"test.png\")]");

and it also produces a 475x525 PNG using DPlot Jr. So I'm out of ideas for now.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

As mentioned in my separate email, I'm suspecting the problem may be in the module that writes the PNG, perhaps FREEIMAGE.DLL or at least the version distributed with DPlot.

As you mentioned, there is at least one problem, the PNG is corrupt. This is clearly a bug -some readers will handle it, Firefox, IE and some others will not. There have been some PNG related changes in the FREEIMAGE.DLL since August 2010, the date on my DPlot supplied copy. What version are you testing with?
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

The same as you - 3.14.1.0 dated 8/12/2010.

I'll look into updating.
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

OK, whatever the problem is, is it's pretty obscure. I'll keep experimenting at this end to see what I can find.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

For what it's worth I just downloaded FreeImage v 3.15.4 and it seems to work fine without recompiling DPlot or the plugins that use it. The previous version also worked fine for me (and I presume most everyone else) so this may not mean much, but when you have time please take a look at http://downloads.sourceforge.net/freeim ... 4Win32.zip
Visualize Your Data
support@dplot.com
rkm
Posts: 27
Joined: Wed Nov 21, 2012 11:15 am

Post by rkm »

Problem found! It was an obscure failure to initialize an index that pointed to formats and format strings in a table. I plan to learn to write bug-free code in some future life. Anyway, the result was that the image was being saved as a WMF with an extension of PNG. The viewer that succeed in loading it recognized it as a WMF in spite of the extension. I haven't yet figured out why the dimension setting was failing. DPlot works fine, as you showed, when actually saving PNGs.

I did indeed download and try FreeImage v 3.15.4 and also found it to work with no problems so far.

Many thanks for all the help -it's the best!
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

I plan to learn to write bug-free code in some future life.
Well if I'm still around (or around again) please let me know how you did it!
:D

Glad you got this worked out.
Visualize Your Data
support@dplot.com
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

I overlooked this earlier:
I haven't yet figured out why the dimension setting was failing.
It wasn't "failing" so much as being ignored. Metafiles are (practically) infinitely scalable with no loss of detail, so a resolution in pixels is pretty much meaningless. If you want to specify the dimensions of a metafile in inches, use SetMetafileDims. If you don't then DPlot will generally size the metafile to match whatever Size values you've used for the width/height of the box around the plot, and default to 6" x 4.5" total if neither is used.
Visualize Your Data
support@dplot.com
Post Reply