Пример #1
0
        public static bool ExportTexture2D(AssetItem item, string exportPath, string format)
        {
            var         converter = new Texture2DConverter((Texture2D)item.Asset);
            ImageFormat dstFormat = ImageFormat.Png;

            if (format == "recommanded" || format == "png")
            {
                format    = "png";
                dstFormat = ImageFormat.Png;
            }
            var oriPath        = item.Asset.assetsFile.originalPath;
            var exportFullName = exportPath + Path.GetFileNameWithoutExtension(oriPath) + "." + format;

            if (format != "original")
            {
                var bitmap = converter.ConvertToBitmap(true);
                if (bitmap == null)
                {
                    return(false);
                }
                bitmap.Save(exportFullName, dstFormat);
                bitmap.Dispose();
                return(true);
            }
            else
            {
                File.WriteAllBytes(exportFullName, converter.ConvertToContainer());
                return(true);
            }
        }
Пример #2
0
        public static bool ExportTexture2D(AssetItem item, string exportPathName)
        {
            var m_Texture2D = new Texture2D(item.reader, true);

            if (m_Texture2D.image_data == null || m_Texture2D.image_data.Length == 0)
            {
                return(false);
            }
            var converter      = new Texture2DConverter(m_Texture2D);
            var convertTexture = (bool)Properties.Settings.Default["convertTexture"];

            if (convertTexture)
            {
                var bitmap = converter.ConvertToBitmap(true);
                if (bitmap == null)
                {
                    return(false);
                }
                ImageFormat format = null;
                var         ext    = (string)Properties.Settings.Default["convertType"];
                switch (ext)
                {
                case "BMP":
                    format = ImageFormat.Bmp;
                    break;

                case "PNG":
                    format = ImageFormat.Png;
                    break;

                case "JPEG":
                    format = ImageFormat.Jpeg;
                    break;
                }
                var exportFullName = exportPathName + item.Text + "." + ext.ToLower();
                if (ExportFileExists(exportFullName))
                {
                    return(false);
                }
                bitmap.Save(exportFullName, format);
                bitmap.Dispose();
                return(true);
            }
            else
            {
                var exportFullName = exportPathName + item.Text + converter.GetExtensionName();
                if (ExportFileExists(exportFullName))
                {
                    return(false);
                }
                File.WriteAllBytes(exportFullName, converter.ConvertToContainer());
                return(true);
            }
        }
Пример #3
0
        public static bool ExportTexture2D(AssetItem item, string exportPathName)
        {
            var converter      = new Texture2DConverter((Texture2D)item.Asset);
            var convertTexture = (bool)Properties.Settings.Default["convertTexture"];

            if (convertTexture)
            {
                var bitmap = converter.ConvertToBitmap(true);
                if (bitmap == null)
                {
                    return(false);
                }
                ImageFormat format = null;
                var         ext    = (string)Properties.Settings.Default["convertType"];
                bool        tga    = false;
                switch (ext)
                {
                case "BMP":
                    format = ImageFormat.Bmp;
                    break;

                case "PNG":
                    format = ImageFormat.Png;
                    break;

                case "JPEG":
                    format = ImageFormat.Jpeg;
                    break;

                case "TGA":
                    tga = true;
                    break;
                }
                var exportFullName = exportPathName + item.Text + "." + ext.ToLower();
                if (ExportFileExists(exportFullName))
                {
                    return(false);
                }
                if (tga)
                {
                    var file = new TGA(bitmap);
                    file.Save(exportFullName);
                }
                else
                {
                    bitmap.Save(exportFullName, format);
                }
                bitmap.Dispose();
                return(true);
            }
            else
            {
                var exportFullName = exportPathName + item.Text + converter.GetExtensionName();
                if (ExportFileExists(exportFullName))
                {
                    return(false);
                }
                File.WriteAllBytes(exportFullName, converter.ConvertToContainer());
                return(true);
            }
        }