having trouble generating .png picture in c++

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

having trouble generating .png picture in c++

xh s
Hi, 

I'm trying to convert a SMILES string to a png picture using openbabel C++ library. Here's a minimal code that says what I want to do. 

#include <openbabel/obconversion.h>
#include <openbabel/mol.h>
#include <openbabel/op.h>
#include <openbabel/plugin.h>
#include <iostream>
using namespace std;
using namespace OpenBabel;

int main() {
  stringstream inputSmiles("CCC(CC)C");
  ofstream pic("minimal_conversion_pic.png");
  OBConversion conv(&inputSmiles, &pic);
  conv.SetInAndOutFormats("smi", "png");
  OBMol mol;
  conv.Read(&mol);
  OBOp* pOp = OBOp::FindType("gen2D");
  pOp->Do(&mol);
  conv.Write(&mol);
}


This compiles and runs fine but it generates a png that's only a few bytes and can't be open. I tried the same code with "png" replaced by "svg" and it worked. However for various reasons I want to use png instead of svg. I guess it might be a cairo issue but I'm not sure. 

Thanks in advance!


Xianghai Sheng

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: having trouble generating .png picture in c++

Geoff Hutchison
> I'm trying to convert a SMILES string to a png picture using openbabel C++ library. Here's a minimal code that says what I want to do.
...
> This compiles and runs fine but it generates a png that's only a few bytes and can't be open. I tried the same code with "png" replaced by "svg" and it worked. However for various reasons I want to use png instead of svg. I guess it might be a cairo issue but I'm not sure.

Ignoring the code for the moment, can you do this from the command line? If not, it has nothing to do with your code.

-Geoff


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: having trouble generating .png picture in c++

xh s
I can do it from command line fine. 

Xianghai

On Thu, May 11, 2017 at 5:33 PM, Geoffrey Hutchison <[hidden email]> wrote:
> I'm trying to convert a SMILES string to a png picture using openbabel C++ library. Here's a minimal code that says what I want to do.
...
> This compiles and runs fine but it generates a png that's only a few bytes and can't be open. I tried the same code with "png" replaced by "svg" and it worked. However for various reasons I want to use png instead of svg. I guess it might be a cairo issue but I'm not sure.

Ignoring the code for the moment, can you do this from the command line? If not, it has nothing to do with your code.

-Geoff



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: having trouble generating .png picture in c++

Fredrik Wallner
Hi,

I think you should use the format "_png2" instead of "png", at least that's how I do it. 

Kind regards,
Fredrik 

Skickat från min iPhone

12 maj 2017 kl. 02:40 skrev xh s <[hidden email]>:

I can do it from command line fine. 

Xianghai

On Thu, May 11, 2017 at 5:33 PM, Geoffrey Hutchison <[hidden email]> wrote:
> I'm trying to convert a SMILES string to a png picture using openbabel C++ library. Here's a minimal code that says what I want to do.
...
> This compiles and runs fine but it generates a png that's only a few bytes and can't be open. I tried the same code with "png" replaced by "svg" and it worked. However for various reasons I want to use png instead of svg. I guess it might be a cairo issue but I'm not sure.

Ignoring the code for the moment, can you do this from the command line? If not, it has nothing to do with your code.

-Geoff


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: having trouble generating .png picture in c++

xh s
That worked! Thank you.

Xianghai

On Thu, May 11, 2017 at 9:28 PM, Fredrik Wallner <[hidden email]> wrote:
Hi,

I think you should use the format "_png2" instead of "png", at least that's how I do it. 

Kind regards,
Fredrik 

Skickat från min iPhone

12 maj 2017 kl. 02:40 skrev xh s <[hidden email]>:

I can do it from command line fine. 

Xianghai

On Thu, May 11, 2017 at 5:33 PM, Geoffrey Hutchison <[hidden email]> wrote:
> I'm trying to convert a SMILES string to a png picture using openbabel C++ library. Here's a minimal code that says what I want to do.
...
> This compiles and runs fine but it generates a png that's only a few bytes and can't be open. I tried the same code with "png" replaced by "svg" and it worked. However for various reasons I want to use png instead of svg. I guess it might be a cairo issue but I'm not sure.

Ignoring the code for the moment, can you do this from the command line? If not, it has nothing to do with your code.

-Geoff


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss