Simple way to save images?
-
Hi,
Is there a simple way to save images?
Here's what I have so far
w = 50 h = 50 image = c4d.bitmaps.BaseBitmap() image.Init(w, h) # creating a black image for illustration image.Save( name="See Appendix A", format=c4d.FILTER_JPG, data="See Appendix B", savebits=SAVEBIT_NONE)
Appendix A:
I was thinking to be just a simpleC:\Users\Luke\Desktop\black_image.jpg
but it requires aUnion[str, c4d.storage.MemoryFileStruct
. There is an existing sample script for it in GitHub. It says it "saves" an image but it doesn't use theBaseBitmap.Save
code so I'm lost how to use it.Appendix B:
I'm not sure what data is this. Isn't theBaseBitmap
the data to be saved? In the example above, theimage
variable. Correct me if I'm wrongIs there a way around this? Thank you for looking at my problem
-
Stupid me. The simple way actually works. I don't have to use the
c4d.storage.MemoryFileStruct
and also use\\
instead of a single\
for the path.Here is the working code:
w = 50 h = 50 image = c4d.bitmaps.BaseBitmap() image.Init(w, h) c4d.bitmaps.ShowBitmap(image) filename = 'C:\\Users\\Luke\\Desktop\\black_image.jpg' image.Save(filename, c4d.FILTER_JPG, c4d.BaseContainer(), c4d.SAVEBIT_NONE)
Here is the thread where I got the sample code. For some reason, reading the documentation sometimes give me more problem than solution.
Anyhow, no further action needed.
-
Hi, @bentraje I'm happy you solved your issue.
@bentraje said in Simple way to save images?:
Stupid me. The simple way actually works. I don't have to use the
c4d.storage.MemoryFileStruct
and also use\\
instead of a single\
for the path.This is more related to python in general so if you write \n it will create a line break. So either you have to escape the backslash to avoid python to think you wanted a line break either you can tell to use this string as it is using raw string by writing an "r" before the string declaration.
rawString = r"C:\Users\Luke\Desktop\black_image.jpg"
@bentraje said in Simple way to save images?:
Here is the thread where I got the sample code. For some reason, reading the documentation sometimes give me more problem than solution.
I'm not sure what's it's unclear in the description of BaseBitmap.Save, maybe the description of name should be
A path to the destination file
?
If you have any feedback please let me know so I can adapt it as soon as possibleCheers,
Maxime. -
Oh so that's the reason for the
r""
code
On the documentation, I'm just confused on the parameterUnion[str, c4d.storage.MemoryFileStruct]
.
I was not sure how to "union" it.
I guess its either or? I mean you can either usestr
or use thec4d.storage.MemoryFileStruct
or both.But again, I have no background in programming. Maybe this is just a common semantics that I missed out on.
-
@bentraje said in Simple way to save images?:
Union
This means it can be either a str or either a c4d.storage.MemoryFileStruct. (Both don't really make sense).
Cheers,
Maxime.