Click here to Skip to main content
15,895,462 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Does anyone know how to read this output from GIMP into an Image?

C#
/* GIMP RGBA C-Source image dump (Smiley.c) */

static const struct {
  guint  	 width;
  guint  	 height;
  guint  	 bytes_per_pixel; /* 3:RGB, 4:RGBA */ 
  guint8 	 pixel_data[15 * 15 * 4 + 1];
} gimp_image = {
  15, 15, 4,
  "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\370\345\261\377"
  "\362\314f\377\357\300C\377\356\2735\377\357\300C\377\362\314f\377\370\345"
  "\261\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
  "\377\0\377\377\377\0\373\362\332\377\357\305W\377\360\307R\377\371\341\211"
  "\377\375\354\242\377\377\362\256\377\375\354\242\377\371\341\211\377\360"
  "\307R\377\357\305W\377\373\362\332\377\377\377\377\0\377\377\377\0\377\377"
  "\377\0\372\361\332\377\353\276H\377\365\330r\377\377\354\231\377\377\352"
  "\231\377\377\353\241\377\377\354\243\377\377\353\241\377\377\352\231\377"
  "\377\354\231\377\365\330r\377\353\276H\377\372\361\332\377\377\377\377\0"
  "\377\377\377\0\351\277W\377\364\325g\377\346\301Y\377\273\210\"\377\273\210"
  "\"\377\345\304k\377\376\347\227\377\345\304k\377\273\210\"\377\273\210\""
  "\377\346\301Y\377\364\325g\377\351\277W\377\377\377\377\0\363\340\261\377"
  "\350\275G\377\376\336i\377\360\311T\377\343\272O\377\343\274T\377\361\315"
  "i\377\376\337}\377\361\315i\377\343\274T\377\343\272O\377\360\311T\377\376"
  "\336i\377\350\275G\377\363\340\261\377\345\277f\377\223|4\3773*\20\377\230"
  "\224\207\377LLL\377\12\24\37\3770(\21\377\213p,\3770(\21\377\205\212\217"
  "\377LLL\3770'\17\3773*\20\377\223|4\377\345\277f\377\334\255C\377\371\323"
  "\\\377:2\27\377XQ<\377CCC\377'1;\3778/\27\377\342\261;\3778/\27\377CLT\377"
  "CCC\377@7\40\377:2\27\377\371\323\\\377\334\255C\377\325\2425\377\374\322"
  "U\377\231w*\377SJ3\377SJ3\377SJ4\377\275\2233\377\356\271:\377\275\2233\377"
  "SJ4\377SJ3\377SJ3\377\230v)\377\374\322U\377\325\2425\377\323\244C\377\366"
  "\310M\377\357\2675\377\341\2531\377\341\2532\377\341\2533\377\364\275<\377"
  "\372\303@\377\364\275<\377\341\2533\377\341\2532\377\341\2531\377\357\267"
  "5\377\366\310M\377\323\244C\377\326\260f\377\352\271D\377\371\2758\377\371"
  "\277;\377\372\300@\377\372\302D\377\372\303F\377\372\303G\377\372\303F\377"
  "\372\302D\377\372\300@\377\371\277;\377\371\2758\377\352\271D\377\326\260"
  "f\377\346\323\261\377\314\2317\377\371\277?\377\371\276@\377\273\210\"\377"
  "\362\275K\377\372\307V\377\372\307W\377\372\307V\377\372\305Q\377\371\302"
  "I\377\371\276@\377\371\277?\377\314\2317\377\346\323\261\377\377\377\377"
  "\0\301\227W\377\333\245=\377\371\300H\377\352\265H\377\273\210\"\377\273"
  "\210\"\377\273\210\"\377\273\210\"\377\343\261H\377\372\305U\377\371\300"
  "H\377\333\245=\377\301\227W\377\377\377\377\0\377\377\377\0\360\347\332\377"
  "\267\210D\377\330\242C\377\371\306[\377\372\313f\377\372\316l\377\372\316"
  "n\377\372\316l\377\372\313f\377\371\306[\377\330\242C\377\267\210D\377\360"
  "\347\332\377\377\377\377\0\377\377\377\0\377\377\377\0\352\343\332\0\271"
  "\217W\377\274\210;\377\337\254O\377\360\277]\377\370\307b\377\360\277]\377"
  "\337\254O\377\274\210;\377\271\217W\377\352\343\332\0\377\377\377\0\377\377"
  "\377\0\377\377\377\0\354\354\354\0\325\325\325\"\312\310\306\377\267\250"
  "\225\377\264\217]\377\257\200B\377\253x5\377\257\200B\377\264\217]\377\267"
  "\250\225\377\314\312\310\356\336\336\336\0\377\377\377\0\377\377\377\0",
};


Thanks,
Don
Posted

If that's XCF, this would hopefully help: http://svn.gnome.org/viewvc/gimp/trunk/devel-docs/xcf.txt?view=markup[^].

However, do you need to use native format or could you save directly to for example JPEG from GIMP?
 
Share this answer
 
I'm not sure what format it is in.

Basically I want a small image to be hard encoded into my code. I don't want to read the image in from an external file. I tried C# Image to Byte Array and Byte Array to Image Converter Class to read the image from an array of bytes, but it lost quality in the image.

I found that GIMP saved as the .c file above but I don't know how to get it into an Image. GIMP can also save as .h but that's even more cryptic. I see that GIMP also saves as .htm with all the pixel rgb values in it. I'll format those rgb's into an array to read in.

Wait a minute, back to C# Image to Byte Array and Byte Array to Image Converter Class. I see that the it was set to ImageFormat.Gif and changing it to ImageFormat.Png fixed the quality. So I'll give that another shot.
 
Share this answer
 
If you're just wanting to embed the image into your executable (i.e. not load it at runtime), you don't need to encode the image into code like this.

You just need to add the image as a resource in Visual Studio, and it will then be available to you in code as a System.Drawing.Bitmap.

See Linked vs. Embedded Resources[^]
How to Add or Remove Resources[^]
Accessing Application Resources[^]

In your case you would save the image as a PNG, GIF, JPG, TIF, etc. and then add it as a resource. Any of those will be available to you in code as a Bitmap.
 
Share this answer
 
No, I don't want it tied to the executable as a resource. I'm happy with it now being part of the .cs file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900