示例#1
0
        private string GetTexture(BaseContainer data, BaseChannel matChannel)
        {
            string resultName = null;
            string texture    = data.GetString(C4dApi.BASECHANNEL_TEXTURE);

            if (!string.IsNullOrEmpty(texture))
            {
                texture    = Path.GetFileNameWithoutExtension(texture);
                texture   += ".jpg";
                resultName = texture;

                if (!_textureFiles.Contains(texture))
                {
                    matChannel.InitTexture(new InitRenderStruct(_doc));
                    using (BaseBitmap bitmap = matChannel.GetBitmap())
                    {
                        if (bitmap != null)
                        {
                            using (BaseContainer compressionContainer = new BaseContainer(C4dApi.JPGSAVER_QUALITY))
                            {
                                bool bRet = bitmap.SetColorProfile(ColorProfile.GetDefaultSRGB());
                                compressionContainer.SetFloat(C4dApi.JPGSAVER_QUALITY, 70.0);
                                string textureFileAbs = Path.Combine(_sceneRootDir, texture);
                                bitmap.Save(new Filename(textureFileAbs), C4dApi.FILTER_JPG, compressionContainer,
                                            SAVEBIT.SAVEBIT_0);
                                _textureFiles.Add(texture);
                            }
                        }
                        else
                        {
                            resultName = null;
                        }
                    }
                    matChannel.FreeTexture();
                }
            }
            return(resultName);
        }