Nikodemus
Member
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?
In CentrEd, it looks like this
On the server, it looks like this.
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.
The question is what is missing for white to be hidden, or where is the problem located?
In CentrEd, it looks like this
On the server, it looks like this.
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);
}
}
Attachments
Last edited: