I'm currently trying to implement an extension in UoFiddler, and I'm facing an issue where everything is imported from the clipboard except for the item list. In CentrEd, it is displayed correctly except for the white outline around it. However, on the server, the image is statically made white. Please refer to the images.
The question is what is missing for white to be hidden, or where is the problem located?
Art922.pngArt921.png
In CentrEd, it looks like this
Art919.png

On the server, it looks like this.

Art926.png

Import function via clipboard:
private void importToolStripclipboardMenuItem_Click(object sender, EventArgs e)
        {
            // Check if the clipboard contains an image
            if (Clipboard.ContainsImage())
            {
                using (Image image = Clipboard.GetImage())
                {
                    Size imageSize = image.Size;
                    int bytesPerPixel = 4; // assuming 32-bit image
                    int imageSizeInBytes = imageSize.Width * imageSize.Height * bytesPerPixel;
                    // use imageSizeInBytes as needed
                }

                // Retrieve the image from the clipboard
                using (Bitmap bmp = new Bitmap(Clipboard.GetImage()))
                {
                    // Get the selected index from the ItemsTileView
                    int index = SelectedGraphicId;

                    if (index >= 0 && index < Art.GetMaxItemId())
                    {
                        // Create a new bitmap with the same size as the image from the clipboard
                        Bitmap newBmp = new Bitmap(bmp.Width, bmp.Height);

                        // Set the resolution of the new bitmap to 96 DPI
                        newBmp.SetResolution(96, 96);

                        // Define the colors to ignore
                        Color[] colorsToIgnore = new Color[]
                        {
                    Color.FromArgb(211, 211, 211), // #D3D3D3
                    Color.FromArgb(0, 0, 0),       // #000000
                    Color.FromArgb(255, 255, 255), // #FFFFFF
                    Color.FromArgb(254, 254, 254)  // #FEFEFE

                        };

                        // Iterate through each pixel of the image
                        for (int x = 0; x < bmp.Width; x++)
                        {
                            for (int y = 0; y < bmp.Height; y++)
                            {
                                // Get the color of the current pixel
                                Color pixelColor = bmp.GetPixel(x, y);

                                // Check if the color of the current pixel is one of the colors to ignore
                                if (colorsToIgnore.Contains(pixelColor))
                                {
                                    // Set the color of the current pixel to transparent
                                    newBmp.SetPixel(x, y, Color.Transparent);
                                }
                                else
                                {
                                    // Set the color of the current pixel to the color of the original image
                                    newBmp.SetPixel(x, y, pixelColor);
                                }
                            }
                        }

                        // Create a new bitmap with the specified pixel format (32-bit)
                        Bitmap finalBmp = newBmp.Clone(new Rectangle(0, 0, newBmp.Width, newBmp.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                        // Replace the image at the specified index
                        Art.ReplaceStatic(index, finalBmp);
                        ControlEvents.FireItemChangeEvent(this, index);

                        // Update the _itemList to insert the index only once
                        if (!_itemList.Contains(index))
                        {
                            _itemList.Add(index);
                            _itemList.Sort();
                        }

                        // Update the VirtualListSize of the ItemsTileView and invalidate the view
                        ItemsTileView.VirtualListSize = _itemList.Count;
                        ItemsTileView.Invalidate();
                        SelectedGraphicId = index;
                        Options.ChangedUltimaClass["Art"] = true;
                    }
                    else
                    {
                        MessageBox.Show("Invalid index.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("No image in the clipboard.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
When I save the file from the clipboard as a BMP and then import it using the Replace method, the graphics appear correctly and transparency is displayed.
 

Attachments

  • 1685573451726.png
    1685573451726.png
    129.5 KB · Views: 1
Last edited:
It has been taken care of so far. I have outsourced it to a temporary directory. However, I am still working on enabling an import function for items using the clipboard. It doesn't seem to be working whether I ignore or convert the colors. Something else must still be set in memory.
 
Alpha channel information is lost when you get image from clipboard. You can use `Utils.ConvertBmp(...);` which will replace black or white color in the bitmap. Handling clipboard is a complex problem as there may be mutliple formats there. So this should work for OnClick handler and black or white background of copied image:

C#:
            if (_selectedGraphicId < 0)
            {
                return;
            }

            IDataObject data = Clipboard.GetDataObject();

            if (data?.GetDataPresent(DataFormats.Bitmap) != true)
            {
                return;
            }

            Bitmap bitmap = (data.GetData(DataFormats.Bitmap,true) as Bitmap);

            bitmap = Utils.ConvertBmp(bitmap);

            Art.ReplaceStatic(_selectedGraphicId, bitmap);

            ControlEvents.FireItemChangeEvent(this, _selectedGraphicId);

            ItemsTileView.Invalidate();
            UpdateToolStripLabels(_selectedGraphicId);
            UpdateDetail(_selectedGraphicId);

            Options.ChangedUltimaClass["Art"] = true;

Here you can read a litte bit more about problems with transparency and winforms Wrestling with Clipboard Images in WPF
 
If then black on white.. whether I define the colors directly as transparent or ask them to convert to white. When importing, as you mentioned, something is lost or not available even if I calculate the file in memory, so something is still missing but will be figured out over time. For now, I'm storing it as a temporary save and saving the sets accordingly. So, making a copy from the clipboard works fine, storing the file temporarily, and then importing it again. I'll figure it out eventually, but for now, I'll just enjoy the sun.
 
Back