private void bs_ImageOpened(object sender, RoutedEventArgs args)
{
try
{
var image = (BitmapImage)sender;
var bitmap = new WriteableBitmap(image);
int width = bitmap.PixelWidth;
int height = bitmap.PixelHeight;
Mipmaps = new Mipmap[1];
Size = new Size2(bitmap.PixelWidth, bitmap.PixelHeight);
var dataPixels = bitmap.Pixels;
var data = new byte[dataPixels.Length * 4];
int i2 = 0;
for (int i = 0; i != dataPixels.Length; ++i)
{
var color = new Color4(dataPixels[i]);
data[i2] = color.R;
data[i2+1] = color.G;
data[i2+2] = color.B;
data[i2+3] = color.A;
i2 += 4;
}
// Flip RB Color bits
for (i2 = 0; i2 != data.Length; i2 += 4)
{
byte c = data[i2];
data[i2] = data[i2+2];
data[i2+2] = c;
}
Mipmaps[0] = new Mipmap(data, width, height, 1, 4);
if (flip) Mipmaps[0].FlipVertical();
}
catch (Exception e)
{
FailedToLoad = true;
Loader.AddLoadableException(e);
if (loadedCallback != null) loadedCallback(this, false);
loadedCallback = null;
return;
}
Loaded = true;
if (loadedCallback != null) loadedCallback(this, true);
loadedCallback = null;
}