private void getOverSizeInfo(int width, int height, ref OverSizeInfo info)
        {
            int width_over_pix  = width - this.Width;
            int height_over_pix = height - this.Height;

            // そもそもオーバーサイズなのか
            if (width_over_pix <= 0 && height_over_pix <= 0)
            {
                info.over_flag = false;
                return;
            }
            info.over_flag = true;

            // 縦横どちらがより多くオーバーしているか
            if (width_over_pix > height_over_pix)
            {
                info.is_width = true;
                info.over_pix = width_over_pix;
            }
            else
            {
                info.is_width = false;
                info.over_pix = height_over_pix;
            }
        }
        private void updatePictureBox()
        {
            //描画先とするImageオブジェクトを作成する
            Bitmap canvas = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            Graphics g = Graphics.FromImage(canvas);

            //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
            //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            if (mediaInfoList.Count <= 0)
            {
                // 要素がない場合は元の画像を削除してから処理を抜ける
                g.Dispose();

                pictureBox1.Image = canvas;
                return;
            }

            int width_index  = 0;
            int height_index = 0;

            for (int i = 0; i < mediaInfoList.Count; i++)
            {
                Image img_obj     = Image.FromFile(mediaInfoList[i].path);
                float raito       = (float)img_obj.Width / (float)img_obj.Height;
                bool  is_portrait = false;
                if (raito < 1)
                {
                    is_portrait = true;
                }

                int width_tmp  = img_obj.Width;
                int height_tmp = img_obj.Height;

                var info = new OverSizeInfo();
                getOverSizeInfo(img_obj.Width, img_obj.Height, ref info);

                if (info.over_flag)
                {
                    if (info.is_width)
                    {
                        width_tmp  = pictureBox1.Width;
                        height_tmp = (int)(pictureBox1.Width / raito);
                    }
                    else
                    {
                        width_tmp  = (int)(pictureBox1.Height * raito);
                        height_tmp = pictureBox1.Height;
                    }
                }
                g.DrawImage(img_obj, width_index, height_index, width_tmp, height_tmp);

                MediaInfo med_info = mediaInfoList[i];
                med_info.now_width  = width_tmp;
                med_info.now_height = height_tmp;
                med_info.now_left   = width_index;
                med_info.now_top    = height_index;
                mediaInfoList[i]    = med_info;

                if (is_portrait)
                {
                    width_index += width_tmp;
                }
                else
                {
                    height_index += height_tmp;
                }

                img_obj.Dispose();
            }


            //Graphicsオブジェクトのリソースを解放する
            g.Dispose();
            //pictureBox1に表示する
            pictureBox1.Image = canvas;
        }
예제 #3
0
    public List <OverSizeInfo> CheckTextureOverMemoSize(float megaBytes)
    {
        List <OverSizeInfo> overSizeList = new List <OverSizeInfo>();

        System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(data.path.TextureDirectoryPath);
        System.IO.FileInfo[]    allFiles      = directoryInfo.GetFiles("*.*", System.IO.SearchOption.AllDirectories);
        for (int i = 0; i < allFiles.Length; i++)
        {
            if ((allFiles[i].Name.Contains(".png") || allFiles[i].Name.Contains(".jpg")) && !allFiles[i].Name.Contains(".meta"))
            {
                if (allFiles[i].Length > megaBytes * 1024 * 1024)
                {
                    string          prefabPath = "Assets" + allFiles[i].FullName.Split(new string[] { "\\Assets" }, 0)[1];
                    Texture         Texture    = AssetDatabase.LoadAssetAtPath <Texture>(prefabPath);
                    TextureImporter m          = AssetImporter.GetAtPath(prefabPath) as TextureImporter;

                    int size = Texture.height * Texture.width * 4;
                    if (size > 1 * 1024 * 1024)
                    {
                        float compressSize = ((float)size) / 1024f / 1024f;
                        switch (m.textureFormat)
                        {
                        case TextureImporterFormat.ETC2_RGB4:
                            compressSize *= 0.125f;
                            break;

                        default:
                            break;
                        }
                        int maxSize = 1024;
                        TextureImporterFormat format = new TextureImporterFormat();
                        m.GetPlatformTextureSettings("Android", out maxSize, out format);
                        switch (format)
                        {
                            #region Formasts

                        case TextureImporterFormat.AutomaticCompressed:
                            break;

                        case TextureImporterFormat.Automatic16bit:
                            break;

                        case TextureImporterFormat.AutomaticTruecolor:
                            break;

                        case TextureImporterFormat.AutomaticCrunched:
                            break;

                        case TextureImporterFormat.DXT1:
                            break;

                        case TextureImporterFormat.DXT5:
                            break;

                        case TextureImporterFormat.RGB16:
                            break;

                        case TextureImporterFormat.RGB24:
                            break;

                        case TextureImporterFormat.Alpha8:
                            break;

                        case TextureImporterFormat.ARGB16:
                            break;

                        case TextureImporterFormat.RGBA32:
                            break;

                        case TextureImporterFormat.ARGB32:
                            break;

                        case TextureImporterFormat.RGBA16:
                            break;

                        case TextureImporterFormat.DXT1Crunched:
                            break;

                        case TextureImporterFormat.DXT5Crunched:
                            break;

                        case TextureImporterFormat.PVRTC_RGB2:
                            break;

                        case TextureImporterFormat.PVRTC_RGBA2:
                            break;

                        case TextureImporterFormat.PVRTC_RGB4:
                            break;

                        case TextureImporterFormat.PVRTC_RGBA4:
                            break;

                        case TextureImporterFormat.ETC_RGB4:
                            break;

                        case TextureImporterFormat.ATC_RGB4:
                            break;

                        case TextureImporterFormat.ATC_RGBA8:
                            break;

                        case TextureImporterFormat.EAC_R:
                            break;

                        case TextureImporterFormat.EAC_R_SIGNED:
                            break;

                        case TextureImporterFormat.EAC_RG:
                            break;

                        case TextureImporterFormat.EAC_RG_SIGNED:
                            break;

                        case TextureImporterFormat.ETC2_RGB4:
                            compressSize *= 0.125f;
                            break;

                        case TextureImporterFormat.ETC2_RGB4_PUNCHTHROUGH_ALPHA:
                            break;

                        case TextureImporterFormat.ETC2_RGBA8:
                            break;

                        case TextureImporterFormat.ASTC_RGB_4x4:
                            break;

                        case TextureImporterFormat.ASTC_RGB_5x5:
                            break;

                        case TextureImporterFormat.ASTC_RGB_6x6:
                            break;

                        case TextureImporterFormat.ASTC_RGB_8x8:
                            break;

                        case TextureImporterFormat.ASTC_RGB_10x10:
                            break;

                        case TextureImporterFormat.ASTC_RGB_12x12:
                            break;

                        case TextureImporterFormat.ASTC_RGBA_4x4:
                            break;

                        case TextureImporterFormat.ASTC_RGBA_5x5:
                            break;

                        case TextureImporterFormat.ASTC_RGBA_6x6:
                            break;

                        case TextureImporterFormat.ASTC_RGBA_8x8:
                            break;

                        case TextureImporterFormat.ASTC_RGBA_10x10:
                            break;

                        case TextureImporterFormat.ASTC_RGBA_12x12:
                            break;

                        default:
                            break;
                            #endregion
                        }
                        //Debug.LogError(prefabPath +" 文件大小:"+(((float)allFiles[i].Length)/1024f/1024f).ToString("0.00")+" MB, 压缩大小:"+compressSize.ToString("0.00")+"MB");
                        OverSizeInfo info = new OverSizeInfo();
                        info.texture       = Texture;
                        info.fileMegaBytes = ((float)allFiles[i].Length) / 1024f / 1024f;
                        info.compressed4AndoridMegaBytes = compressSize;
                        overSizeList.Add(info);
                    }
                }
            }
        }
        return(overSizeList);
    }