ConvertBmp() public static method

public static ConvertBmp ( Bitmap bmp ) : Bitmap
bmp System.Drawing.Bitmap
return System.Drawing.Bitmap
Beispiel #1
0
 private void onClickReplace(object sender, EventArgs e)
 {
     if (listBox.SelectedItems.Count == 1)
     {
         using (OpenFileDialog dialog = new OpenFileDialog())
         {
             dialog.Multiselect     = false;
             dialog.Title           = "Choose image file to replace";
             dialog.CheckFileExists = true;
             dialog.Filter          = "Image files (*.tif;*.tiff;*.bmp)|*.tif;*.tiff;*.bmp";
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 Bitmap bmp = new Bitmap(dialog.FileName);
                 if (dialog.FileName.Contains(".bmp"))
                 {
                     bmp = Utils.ConvertBmp(bmp);
                 }
                 int i = int.Parse(listBox.Items[listBox.SelectedIndex].ToString());
                 Gumps.ReplaceGump(i, bmp);
                 FiddlerControls.Events.FireGumpChangeEvent(this, i);
                 listBox.Invalidate();
                 listBox_SelectedIndexChanged(this, EventArgs.Empty);
                 Options.ChangedUltimaClass["Gumps"] = true;
             }
         }
     }
 }
Beispiel #2
0
 private void onClickReplace(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count == 1)
     {
         using (OpenFileDialog dialog = new OpenFileDialog())
         {
             dialog.Multiselect     = false;
             dialog.Title           = "Choose image file to replace";
             dialog.CheckFileExists = true;
             dialog.Filter          = "Image files (*.tif;*.tiff;*.bmp)|*.tif;*.tiff;*.bmp";
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 Bitmap bmp = new Bitmap(dialog.FileName);
                 if (((bmp.Width == 64) && (bmp.Height == 64)) || ((bmp.Width == 128) && (bmp.Height == 128)))
                 {
                     if (dialog.FileName.Contains(".bmp"))
                     {
                         bmp = Utils.ConvertBmp(bmp);
                     }
                     int i = (int)listView1.SelectedItems[0].Tag;
                     Textures.Replace(i, bmp);
                     FiddlerControls.Events.FireTextureChangeEvent(this, i);
                     listView1.Invalidate();
                     listView_SelectedIndexChanged(this, (ListViewItemSelectionChangedEventArgs)null);
                     Options.ChangedUltimaClass["Texture"] = true;
                 }
                 else
                 {
                     MessageBox.Show("Height or Width Invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                 }
             }
         }
     }
 }
Beispiel #3
0
 private void onClickReplace(object sender, EventArgs e)
 {
     if (selected >= 0)
     {
         using (OpenFileDialog dialog = new OpenFileDialog())
         {
             dialog.Multiselect     = false;
             dialog.Title           = "Choose image file to replace";
             dialog.CheckFileExists = true;
             dialog.Filter          = "image files (*.tiff;*.bmp)|*.tiff;*.bmp";
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 Bitmap bmp = new Bitmap(dialog.FileName);
                 if (dialog.FileName.Contains(".bmp"))
                 {
                     bmp = Utils.ConvertBmp(bmp);
                 }
                 Art.ReplaceLand(selected, bmp);
                 FiddlerControls.Events.FireLandTileChangeEvent(this, selected);
                 pictureBox.Invalidate();
                 Options.ChangedUltimaClass["Art"] = true;
             }
         }
     }
 }
Beispiel #4
0
 private void OnClickReplace(object sender, EventArgs e)
 {
     if (treeView1.SelectedNode != null)
     {
         using (OpenFileDialog dialog = new OpenFileDialog())
         {
             dialog.Multiselect     = false;
             dialog.Title           = "Choose image file to replace";
             dialog.CheckFileExists = true;
             dialog.Filter          = "Image files (*.tif;*.tiff;*.bmp)|*.tif;*.tiff;*.bmp";
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 Bitmap bmp = new Bitmap(dialog.FileName);
                 if (dialog.FileName.Contains(".bmp"))
                 {
                     bmp = Utils.ConvertBmp(bmp);
                 }
                 int i = (int)treeView1.SelectedNode.Tag;
                 Ultima.Light.Replace(i, bmp);
                 treeView1.Invalidate();
                 AfterSelect(this, (TreeViewEventArgs)null);
                 Options.ChangedUltimaClass["Light"] = true;
             }
         }
     }
 }
Beispiel #5
0
 private void OnClickReplace(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count == 1)
     {
         using (OpenFileDialog dialog = new OpenFileDialog())
         {
             dialog.Multiselect     = false;
             dialog.Title           = "Choose image file to replace";
             dialog.CheckFileExists = true;
             dialog.Filter          = "Image files (*.tif;*.tiff;*.bmp)|*.tif;*.tiff;*.bmp";
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 Bitmap bmp = new Bitmap(dialog.FileName);
                 if ((bmp.Height != 44) || (bmp.Width != 44))
                 {
                     MessageBox.Show("Height or Width Invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                     return;
                 }
                 if (dialog.FileName.Contains(".bmp"))
                 {
                     bmp = Utils.ConvertBmp(bmp);
                 }
                 int id = (int)listView1.SelectedItems[0].Tag;
                 if (id == -1)
                 {
                     listView1.SelectedItems[0].Tag = id = listView1.SelectedItems[0].Index;
                 }
                 Art.ReplaceLand(id, bmp);
                 FiddlerControls.Events.FireLandTileChangeEvent(this, id);
                 listView1.Invalidate();
                 Options.ChangedUltimaClass["Art"] = true;
             }
         }
     }
 }
Beispiel #6
0
 private void OnClickReplace(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count > 0)
     {
         using (OpenFileDialog dialog = new OpenFileDialog())
         {
             int frameindex = (int)listView1.SelectedItems[0].Tag;
             dialog.Multiselect     = false;
             dialog.Title           = String.Format("Выбирите файлы изображений, которым хотите заменить {0}й кадр.", frameindex);
             dialog.CheckFileExists = true;
             dialog.Filter          = "файлы изображений (*.tiff;*.bmp)|*.tiff;*.bmp";
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 Bitmap bmp = new Bitmap(dialog.FileName);
                 if (dialog.FileName.Contains(".bmp"))
                 {
                     bmp = Utils.ConvertBmp(bmp);
                 }
                 AnimIdx edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir);
                 if (edit != null)
                 {
                     edit.ReplaceFrame(bmp, frameindex);
                     listView1.Invalidate();
                     Options.ChangedUltimaClass["Animations"] = true;
                 }
             }
         }
     }
 }
Beispiel #7
0
 private void OnClickReplace(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count == 1)
     {
         using (OpenFileDialog dialog = new OpenFileDialog())
         {
             dialog.Multiselect     = false;
             dialog.Title           = "Choose image file to replace";
             dialog.CheckFileExists = true;
             dialog.Filter          = "image files (*.tiff;*.bmp)|*.tiff;*.bmp";
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 Bitmap bmp = new Bitmap(dialog.FileName);
                 if (dialog.FileName.Contains(".bmp"))
                 {
                     bmp = Utils.ConvertBmp(bmp);
                 }
                 int id = (int)listView1.SelectedItems[0].Tag;
                 if (id == -1)
                 {
                     listView1.SelectedItems[0].Tag = id = listView1.SelectedItems[0].Index;
                 }
                 Art.ReplaceStatic(id, bmp);
                 FiddlerControls.Events.FireItemChangeEvent(this, id);
                 listView1.Invalidate();
                 UpdateDetail(id);
                 Options.ChangedUltimaClass["Art"] = true;
             }
         }
     }
 }
Beispiel #8
0
 private void onKeyDownInsert(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         int index;
         if (Utils.ConvertStringToInt(InsertText.Text, out index, 0, 0xFFF))
         {
             if (Textures.TestTexture(index))
             {
                 return;
             }
             contextMenuStrip1.Close();
             using (OpenFileDialog dialog = new OpenFileDialog())
             {
                 dialog.Multiselect     = false;
                 dialog.Title           = String.Format("Choose image file to insert at 0x{0:X}", index);
                 dialog.CheckFileExists = true;
                 dialog.Filter          = "image files (*.tiff;*.bmp)|*.tiff;*.bmp";
                 if (dialog.ShowDialog() == DialogResult.OK)
                 {
                     Bitmap bmp = new Bitmap(dialog.FileName);
                     if (((bmp.Width == 64) && (bmp.Height == 64)) || ((bmp.Width == 128) && (bmp.Height == 128)))
                     {
                         if (dialog.FileName.Contains(".bmp"))
                         {
                             bmp = Utils.ConvertBmp(bmp);
                         }
                         Textures.Replace(index, bmp);
                         FiddlerControls.Events.FireTextureChangeEvent(this, index);
                         bool done = false;
                         for (int i = 0; i < TextureList.Count; ++i)
                         {
                             if (index < TextureList[i])
                             {
                                 TextureList.Insert(i, index);
                                 vScrollBar.Value = i / refMarker.col + 1;
                                 done             = true;
                                 break;
                             }
                         }
                         if (!done)
                         {
                             TextureList.Add(index);
                             vScrollBar.Value = TextureList.Count / refMarker.col + 1;
                         }
                         selected          = index;
                         GraphicLabel.Text = String.Format("Graphic: 0x{0:X4} ({0}) [{1}x{1}]", selected, Textures.GetTexture(selected));
                         pictureBox.Invalidate();
                         Options.ChangedUltimaClass["Texture"] = true;
                     }
                     else
                     {
                         MessageBox.Show("Height or Width Invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                     }
                 }
             }
         }
     }
 }
Beispiel #9
0
 private void onKeyDownInsert(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         int index;
         if (Utils.ConvertStringToInt(InsertText.Text, out index, 0, 0x3FFF))
         {
             if (Art.IsValidLand(index))
             {
                 return;
             }
             contextMenuStrip1.Close();
             using (OpenFileDialog dialog = new OpenFileDialog())
             {
                 dialog.Multiselect     = false;
                 dialog.Title           = String.Format("Choose image file to insert at 0x{0:X}", index);
                 dialog.CheckFileExists = true;
                 dialog.Filter          = "image files (*.tiff;*.bmp)|*.tiff;*.bmp";
                 if (dialog.ShowDialog() == DialogResult.OK)
                 {
                     Bitmap bmp = new Bitmap(dialog.FileName);
                     if (dialog.FileName.Contains(".bmp"))
                     {
                         bmp = Utils.ConvertBmp(bmp);
                     }
                     Art.ReplaceLand(index, bmp);
                     FiddlerControls.Events.FireLandTileChangeEvent(this, index);
                     bool done = false;
                     for (int i = 0; i < TileList.Count; ++i)
                     {
                         if (index < TileList[i])
                         {
                             TileList.Insert(i, index);
                             vScrollBar.Value = i / refMarker.col + 1;
                             done             = true;
                             break;
                         }
                     }
                     if (!done)
                     {
                         TileList.Add(index);
                         vScrollBar.Value = TileList.Count / refMarker.col + 1;
                     }
                     Selected = index;
                     Options.ChangedUltimaClass["Art"] = true;
                 }
             }
         }
     }
 }
Beispiel #10
0
        private void onKeydown_InsertText(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
            {
                return;
            }

            int index;

            if (Utils.ConvertStringToInt(InsertText.Text, out index, 0, Gumps.GetCount()))
            {
                if (Gumps.IsValidIndex(index))
                {
                    return;
                }
                contextMenuStrip1.Close();
                using (OpenFileDialog dialog = new OpenFileDialog())
                {
                    dialog.Multiselect     = false;
                    dialog.Title           = String.Format("Choose image file to insert at 0x{0:X}", index);
                    dialog.CheckFileExists = true;
                    dialog.Filter          = "Image files (*.tif;*.tiff;*.bmp)|*.tif;*.tiff;*.bmp";
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        Bitmap bmp = new Bitmap(dialog.FileName);
                        if (dialog.FileName.Contains(".bmp"))
                        {
                            bmp = Utils.ConvertBmp(bmp);
                        }
                        Gumps.ReplaceGump(index, bmp);
                        FiddlerControls.Events.FireGumpChangeEvent(this, index);
                        bool done = false;
                        for (int i = 0; i < listBox.Items.Count; ++i)
                        {
                            int j = int.Parse(listBox.Items[i].ToString());
                            if (j > index)
                            {
                                listBox.Items.Insert(i, index);
                                listBox.SelectedIndex = i;
                                done = true;
                                break;
                            }
                            else if (ShowFreeSlots)
                            {
                                if (j == i)
                                {
                                    listBox.SelectedIndex = i;
                                    done = true;
                                    break;
                                }
                            }
                        }
                        if (!done)
                        {
                            listBox.Items.Add(index);
                            listBox.SelectedIndex = listBox.Items.Count - 1;
                        }
                        Options.ChangedUltimaClass["Gumps"] = true;
                    }
                }
            }
        }
 private void onKeyDownInsertText(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         int index;
         if (Utils.ConvertStringToInt(InsertText.Text, out index, 0, Ultima.Art.GetMaxItemID()))
         {
             if (Art.IsValidStatic(index))
             {
                 return;
             }
             contextMenuStrip1.Close();
             using (OpenFileDialog dialog = new OpenFileDialog())
             {
                 dialog.Multiselect     = false;
                 dialog.Title           = String.Format("Choose image file to insert at 0x{0:X}", index);
                 dialog.CheckFileExists = true;
                 dialog.Filter          = "image files (*.tiff;*.bmp)|*.tiff;*.bmp";
                 if (dialog.ShowDialog() == DialogResult.OK)
                 {
                     Bitmap bmp = new Bitmap(dialog.FileName);
                     if (dialog.FileName.Contains(".bmp"))
                     {
                         bmp = Utils.ConvertBmp(bmp);
                     }
                     Art.ReplaceStatic(index, bmp);
                     FiddlerControls.Events.FireItemChangeEvent(this, index);
                     Options.ChangedUltimaClass["Art"] = true;
                     if (ShowFreeSlots)
                     {
                         selected          = index;
                         vScrollBar.Value  = index / refMarker.col + 1;
                         namelabel.Text    = String.Format("Name: {0}", TileData.ItemTable[selected].Name);
                         graphiclabel.Text = String.Format("Graphic: 0x{0:X4} ({0})", selected);
                         UpdateDetail(selected);
                         pictureBox.Invalidate();
                     }
                     else
                     {
                         bool done = false;
                         for (int i = 0; i < ItemList.Count; ++i)
                         {
                             if (index < ItemList[i])
                             {
                                 ItemList.Insert(i, index);
                                 vScrollBar.Value = i / refMarker.col + 1;
                                 done             = true;
                                 break;
                             }
                         }
                         if (!done)
                         {
                             ItemList.Add(index);
                             vScrollBar.Value = ItemList.Count / refMarker.col + 1;
                         }
                         selected          = index;
                         namelabel.Text    = String.Format("Name: {0}", TileData.ItemTable[selected].Name);
                         graphiclabel.Text = String.Format("Graphic: 0x{0:X4} ({0})", selected);
                         UpdateDetail(selected);
                         pictureBox.Invalidate();
                     }
                 }
             }
         }
     }
 }
Beispiel #12
0
 private void OnKeyDown_Insert(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         int index;
         if (Utils.ConvertStringToInt(InsertText.Text, out index, 0, 0x3FFF))
         {
             if (Art.IsValidLand(index))
             {
                 return;
             }
             contextMenuStrip1.Close();
             using (OpenFileDialog dialog = new OpenFileDialog())
             {
                 dialog.Multiselect     = false;
                 dialog.Title           = String.Format("Choose image file to insert at 0x{0:X}", index);
                 dialog.CheckFileExists = true;
                 dialog.Filter          = "Image files (*.tif;*.tiff;*.bmp)|*.tif;*.tiff;*.bmp";
                 if (dialog.ShowDialog() == DialogResult.OK)
                 {
                     Bitmap bmp = new Bitmap(dialog.FileName);
                     if ((bmp.Height != 44) || (bmp.Width != 44))
                     {
                         MessageBox.Show("Height or Width Invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                         return;
                     }
                     if (dialog.FileName.Contains(".bmp"))
                     {
                         bmp = Utils.ConvertBmp(bmp);
                     }
                     Art.ReplaceLand(index, bmp);
                     FiddlerControls.Events.FireLandTileChangeEvent(this, index);
                     Options.ChangedUltimaClass["Art"] = true;
                     ListViewItem item = new ListViewItem(index.ToString(), 0);
                     item.Tag = index;
                     if (ShowFreeSlots)
                     {
                         listView1.Items[index] = item;
                         listView1.Invalidate();
                     }
                     else
                     {
                         bool done = false;
                         foreach (ListViewItem i in listView1.Items)
                         {
                             if ((int)i.Tag > index)
                             {
                                 listView1.Items.Insert(i.Index, item);
                                 done = true;
                                 break;
                             }
                         }
                         if (!done)
                         {
                             listView1.Items.Add(item);
                         }
                     }
                     listView1.View = View.Details; // that works faszinating
                     listView1.View = View.Tile;
                     if (listView1.SelectedItems.Count == 1)
                     {
                         listView1.SelectedItems[0].Selected = false;
                     }
                     item.Selected = true;
                     item.Focused  = true;
                     item.EnsureVisible();
                 }
             }
         }
     }
 }
Beispiel #13
0
        private void OnClickAdd(object sender, EventArgs e)
        {
            if (FileType != 0)
            {
                using (OpenFileDialog dialog = new OpenFileDialog())
                {
                    dialog.Multiselect     = true;
                    dialog.Title           = "Выбирите файлы изображений для добавления";
                    dialog.CheckFileExists = true;
                    dialog.Filter          = "файлы изображений (*.tiff;*.bmp)|*.tiff;*.bmp";
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        listView1.BeginUpdate();
                        foreach (string filename in dialog.FileNames)
                        {
                            Bitmap bmp = new Bitmap(filename);
                            if (dialog.FileName.Contains(".bmp"))
                            {
                                if (useCKeyFilter)
                                {
                                    bmp = Utils.CKeyFilter(bmp);
                                }
                                if (useBColFilter)
                                {
                                    bmp = Utils.BColFilter(bmp, false);
                                }

                                bmp = Utils.ConvertBmp(bmp);
                            }
                            AnimIdx edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir);
                            if (edit != null)
                            {
                                edit.AddFrame(bmp);
                                TreeNode node = GetNode(CurrBody);
                                if (node != null)
                                {
                                    node.ForeColor = Color.Black;
                                    node.Nodes[CurrAction].ForeColor = Color.Black;
                                }
                                ListViewItem item;
                                int          i = edit.Frames.Count - 1;
                                item     = new ListViewItem(i.ToString(), 0);
                                item.Tag = i;
                                listView1.Items.Add(item);
                                int width = listView1.TileSize.Width - 5;
                                if (bmp.Width > listView1.TileSize.Width)
                                {
                                    width = bmp.Width;
                                }
                                int height = listView1.TileSize.Height - 5;
                                if (bmp.Height > listView1.TileSize.Height)
                                {
                                    height = bmp.Height;
                                }

                                listView1.TileSize = new Size(width + 5, height + 5);
                                trackBar2.Maximum  = i;
                                Options.ChangedUltimaClass["Animations"] = true;
                            }
                        }
                        listView1.EndUpdate();
                        listView1.Invalidate();
                    }
                }
            }
        }
Beispiel #14
0
        private unsafe void OnClickAddGen(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Multiselect     = true;
                dialog.Title           = "Выбирите файлы изображений для добавления. Напоминание: для выбранных изображений будет сгенерирована палитра, которая заменит старую.";
                dialog.CheckFileExists = true;
                dialog.Filter          = "файлы изображений (*.tiff;*.bmp)|*.tiff;*.bmp";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // Получаем палитру
                    ushort[] Palette = new ushort[0x100];
                    int      count   = 0;
                    foreach (string filename in dialog.FileNames)
                    {
                        Bitmap bmp = new Bitmap(filename);
                        if (dialog.FileName.Contains(".bmp"))
                        {
                            if (useCKeyFilter)
                            {
                                bmp = Utils.CKeyFilter(bmp);
                            }
                            if (useBColFilter)
                            {
                                bmp = Utils.BColFilter(bmp, false);
                            }

                            bmp = Utils.ConvertBmp(bmp);
                        }

                        BitmapData bd    = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);
                        ushort *   line  = (ushort *)bd.Scan0;
                        int        delta = bd.Stride >> 1;
                        ushort *   cur   = line;
                        for (int y = 0; y < bmp.Height; ++y, line += delta)
                        {
                            cur = line;
                            for (int x = 0; x < bmp.Width; ++x)
                            {
                                ushort c = cur[x];
                                if (c != 0)
                                {
                                    bool found = false;
                                    for (int i = 0; i < Palette.Length; ++i)
                                    {
                                        if (Palette[i] == c)
                                        {
                                            found = true;
                                            break;
                                        }
                                    }
                                    if (!found)
                                    {
                                        Palette[count++] = c;
                                    }
                                    if (count >= 0x100)
                                    {
                                        MessageBox.Show(
                                            "Используется больше чем 0x100 (256) цветов!",
                                            "Генерация палитры",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error,
                                            MessageBoxDefaultButton.Button1);
                                        return;
                                    }
                                }
                            }
                        }
                    }

                    // Устанавливаем палитру
                    AnimIdx edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir);
                    if (edit != null)
                    {
                        edit.ReplacePalette(Palette);
                        SetPaletteBox();
                        listView1.Invalidate();
                        Options.ChangedUltimaClass["Animations"] = true;
                    }
                    else
                    {
                        MessageBox.Show(
                            String.Format("Палитра не может быть применена в данный момент, из-за выполняемых действий."),
                            "Генерация палитры",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information,
                            MessageBoxDefaultButton.Button1);
                        return;
                    }

                    // Добавляем кадры
                    listView1.BeginUpdate();
                    foreach (string filename in dialog.FileNames)
                    {
                        Bitmap bmp = new Bitmap(filename);
                        if (filename.Contains(".bmp"))
                        {
                            if (useCKeyFilter)
                            {
                                bmp = Utils.CKeyFilter(bmp);
                            }
                            if (useBColFilter)
                            {
                                bmp = Utils.BColFilter(bmp, false);
                            }

                            bmp = Utils.ConvertBmp(bmp);
                        }
                        AnimIdx edit2 = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir);
                        if (edit2 != null)
                        {
                            edit2.AddFrame(bmp);
                            TreeNode node = GetNode(CurrBody);
                            if (node != null)
                            {
                                node.ForeColor = Color.Black;
                                node.Nodes[CurrAction].ForeColor = Color.Black;
                            }
                            ListViewItem item;
                            int          i = edit2.Frames.Count - 1;
                            item     = new ListViewItem(i.ToString(), 0);
                            item.Tag = i;
                            listView1.Items.Add(item);
                            int width = listView1.TileSize.Width - 5;
                            if (bmp.Width > listView1.TileSize.Width)
                            {
                                width = bmp.Width;
                            }
                            int height = listView1.TileSize.Height - 5;
                            if (bmp.Height > listView1.TileSize.Height)
                            {
                                height = bmp.Height;
                            }

                            listView1.TileSize = new Size(width + 5, height + 5);
                            trackBar2.Maximum  = i;
                            Options.ChangedUltimaClass["Animations"] = true;
                        }
                    }
                    listView1.EndUpdate();
                    listView1.Invalidate();
                }
            }
        }
Beispiel #15
0
        private unsafe void OnClickGeneratePalette(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Multiselect     = true;
                dialog.Title           = "Выбирите изображения для которых хотите сгенерировать палитру";
                dialog.CheckFileExists = true;
                dialog.Filter          = "файлы изображений (*.tiff;*.bmp)|*.tiff;*.bmp";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    ushort[] Palette = new ushort[0x100];
                    int      count   = 0;
                    foreach (string filename in dialog.FileNames)
                    {
                        Bitmap bmp = new Bitmap(filename);
                        if (dialog.FileName.Contains(".bmp"))
                        {
                            bmp = Utils.ConvertBmp(bmp);
                        }

                        BitmapData bd    = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);
                        ushort *   line  = (ushort *)bd.Scan0;
                        int        delta = bd.Stride >> 1;
                        ushort *   cur   = line;
                        for (int y = 0; y < bmp.Height; ++y, line += delta)
                        {
                            cur = line;
                            for (int x = 0; x < bmp.Width; ++x)
                            {
                                ushort c = cur[x];
                                if (c != 0)
                                {
                                    bool found = false;
                                    for (int i = 0; i < Palette.Length; ++i)
                                    {
                                        if (Palette[i] == c)
                                        {
                                            found = true;
                                            break;
                                        }
                                    }
                                    if (!found)
                                    {
                                        Palette[count++] = c;
                                    }
                                    if (count >= 0x100)
                                    {
                                        MessageBox.Show(
                                            "Используется больше чем 0x100 (256) цветов!",
                                            "Генерация палитры",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error,
                                            MessageBoxDefaultButton.Button1);
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    string path     = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                    string FileName = Path.Combine(path, "generated palette.txt");
                    using (StreamWriter Tex = new StreamWriter(new FileStream(FileName, FileMode.Create, FileAccess.ReadWrite)))
                    {
                        for (int i = 0; i < 0x100; ++i)
                        {
                            Tex.WriteLine(Palette[i]);
                        }
                    }
                    MessageBox.Show(
                        String.Format("Палитра сохранена в {0}", FileName),
                        "Генерация палитры",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information,
                        MessageBoxDefaultButton.Button1);
                }
            }
        }