Пример #1
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            if (!InputFormRef.CheckWriteProtectionID00())
            {
                return;
            }

            string imagefilename = ImageFormRef.OpenFilenameDialogFullColor(this);

            if (imagefilename == "")
            {
                return;
            }

            Bitmap fullColor = ImageUtil.OpenLowBitmap(imagefilename); //bitmapそのものの色で開く.

            if (fullColor == null)
            {
                return;
            }

            if (fullColor.Width == 128 && fullColor.Height == 112)
            {
                Bitmap seetbitmap;
                if (ImageUtil.Is16ColorBitmap(fullColor))
                {
                    seetbitmap = ImageUtil.OpenBitmap(imagefilename); //16色に変換して開く.
                    if (seetbitmap == null)
                    {
                        fullColor.Dispose();
                        return;
                    }
                    seetbitmap = ImageUtil.ConvertPaletteTransparentUI(seetbitmap);
                    if (seetbitmap == null)
                    {
                        fullColor.Dispose();
                        return;
                    }
                }
                else
                {//取り込めないので提案をする.
                    ImagePortraitImporterForm f = (ImagePortraitImporterForm)InputFormRef.JumpFormLow <ImagePortraitImporterForm>();
                    f.SetOrignalImage(fullColor
                                      , 0, 0, (int)this.B12.Value, (int)this.B13.Value);
                    f.ShowDialog();

                    seetbitmap = f.GetResultBitmap();
                    if (seetbitmap == null)
                    {
                        fullColor.Dispose();
                        return;
                    }
                    if (f.IsDetailMode())
                    {
                        U.ForceUpdate(this.B12, f.GetMouthBlockX());
                        U.ForceUpdate(this.B13, f.GetMouthBlockY());
                    }
                }

                Bitmap seet;
                Bitmap map_face;
                BuildPortraitSeetFE6(seetbitmap, out seet, out map_face);

                byte[] seet_image = ImageUtil.ImageToByte16Tile(seet, seet.Width, seet.Height);
                seet_image = U.subrange(seet_image, 0, (uint)(seet_image.Length - (3 * (8 * 8 / 2) * 8))); //FE6の場合データサイズがさらに小さくなる
                byte[] map_face_image = ImageUtil.ImageToByte16Tile(map_face, map_face.Width, map_face.Height);
                byte[] palette        = ImageUtil.ImageToPalette(seet, 1);


                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    //画像等データの書き込み
                    Undo.UndoData undodata = Program.Undo.NewUndoData(this);
                    this.InputFormRef.WriteImageData(this.D0, seet_image, true, undodata);      //FE6は顔画像も圧縮する
                    this.InputFormRef.WriteImageData(this.D4, map_face_image, false, undodata); //FE6のマップ顔は無圧縮
                    this.InputFormRef.WriteImageData(this.D8, palette, false, undodata);
                    Program.Undo.Push(undodata);
                }

                //ポインタの書き込み
                this.WriteButton.PerformClick();
            }
            else if (fullColor.Width == 80 &&
                     (fullColor.Height == 80 || fullColor.Height == 72))
            {
                Bitmap seetbitmap = ImageUtil.OpenBitmap(imagefilename); //16色に変換して開く.
                if (seetbitmap == null)
                {
                    fullColor.Dispose();
                    return;
                }
                seetbitmap = ImageUtil.ConvertPaletteTransparentUI(seetbitmap);
                if (seetbitmap == null)
                {
                    fullColor.Dispose();
                    return;
                }

                byte[] class_image = ImageUtil.ImageToByte16Tile(seetbitmap, seetbitmap.Width, seetbitmap.Height);
                byte[] palette     = ImageUtil.ImageToPalette(seetbitmap, 1);

                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    //画像等データの書き込み
                    Undo.UndoData undodata = Program.Undo.NewUndoData(this);
                    this.InputFormRef.WriteImageData(this.D0, class_image, true, undodata); //クラス画像は圧縮されている.
                    this.InputFormRef.WriteImageData(this.D8, palette, false, undodata);
                    Program.Undo.Push(undodata);
                }

                //顔パラメーターは使わないので0を入れる.
                U.ForceUpdate(this.D4, 0);
                U.ForceUpdate(this.B12, 0);
                U.ForceUpdate(this.B13, 0);

                //ポインタの書き込み
                this.WriteButton.PerformClick();
            }
            else
            {
                R.ShowStopError("画像サイズが正しくありません。\r\n顔画像ならば、128x112 \r\nクラス画像ならば 80x80 である必要があります。\r\n\r\n選択された画像のサイズ Width:{0} Height:{1}", fullColor.Width, fullColor.Height, Width, Height);
            }
        }