View Full Version : How to save a custom image on disk.
ThrawnCG 07-21-2006, 06:00 AM Hello!!
I need to save a custom image on disk from maya. I want do built the image pixel by pixel, RBG by RBG, then save on disk using the name and format I want.
Ex: pixel 1 -> R:100 G:120 B:80 ; pixel 2 -> R:20 G:30 B:100 ... etc...
How do I do that?
Thanks!
|
|
Robert Bateman
07-21-2006, 09:19 AM
the MImage class in the Maya API.
ThrawnCG
07-21-2006, 04:20 PM
Only using the API ?? Thatīll be a problem...
Is there any other way of doing this in MEL ?
Maybe if I had other standalone program that creates a image, could I use MEL to call it and pass the parameters?
Thks.
Robert Bateman
07-21-2006, 05:38 PM
Only using the API ?? Thatīll be a problem...
why?
unsigned char* pixels = new unsigned char[256*256*4];
memset(pixels,0,256*256*4);
// fill pixels array
MImage img;
img.setPixels(pixels,256,256);
img.writeToFile("C:/image.tif");
img.release();
delete [] pixels ;
you will never find a simpler way to do it in mel.
Maybe if I had other standalone program that creates a image, could I use MEL to call it and pass the parameters?
that'll be an awful lot of parameters to pass around. For just a 256x256 image you'll need to send 65536 pixels, or 196608 seperate RGB values.... A text string containing that lot would require at least 1Mb of storage space for your command line arg. Other than being incredibly slow to create that, it just isn't practical.
No matter what you think you want to use mel for, handling vast quantities of image data is definately NOT something mel will ever be able to handle.
Use the API. It is by far the simplest possible way of doing this. mel does have file writing funcs, but none has the level of control to write binary data of this sort. At best, you could use mel to write the image data as ascii into a text file, then write your own C++ app to convert it into a readable image file. This of course would be far more work than simply using C++ and the Maya API to begin with.
probably the easiest way is to simply expose the MImage funcs as mel commands. Then you could do :
mySetImageSize -w 256 -h 256;
mySetPixel -x 0 -y 0 -rgb 255 0 0;
mySetPixel -x 1 -y 0 -rgb 255 0 0;
/* snip */
mySaveImage -file "C:/image.tif";
myRelease;
ThrawnCG
07-21-2006, 09:19 PM
Hello. Thanks for all the explanation.
The problem is that I only have Dev-C++ available... The Maya API runs with it?
I have no experience to use apiīs also, the way to link the files with the compiler and so on are still a mistery to me.
The result will be a mll file ?
Thinking better, I need a system to keep a image in memory, and only when the user wants it should be saved on disk. Saving every time will be very slow...
Iīm trying to build a script that works similar to the 3D Paint tool, where I "paint" on a face and the script creates a texture based on some calculations I have to do. Then it should be updated on the objct (it will be used as a normal map, so with the high quality rendering enabled in the viewport I can see the effect of the "paint" in the "bump" of the object, in real-time.)
So only storing this image in memory, applying and updating it on object will be great (and faster) for now. I tryed to use the art3dPaintCtx, because it does what I want; but couldnīt find those flags I wanted in this command.
ThrawnCG
08-01-2006, 07:33 PM
Hello.
Can you tell me exactly how to expose the MImage funcs as mel commands?
Thanks!
Robert Bateman
08-02-2006, 01:24 PM
there's an example on my website that does it. It's one of the function examples in the api section.
ThrawnCG
08-03-2006, 06:17 PM
Ok, thank you, Iīm looking at your tutorials.
I read somewhere that I could use attributes do store data between MEL and API, is that possible? I donīt know exactly what kind or where is that attribute (a special node?), but I
could store a array there using mel and use the api to get back, only informing the name of the attribute.
Is that possible?
CGTalk Moderation
08-03-2006, 06:17 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.