UWT now supports DrawImage
This commit is contained in:
parent
53ca5abdfc
commit
40f453c391
@ -54,7 +54,9 @@ namespace UniversalEditor.Controls.DrawingArea
|
||||
else
|
||||
{
|
||||
Console.WriteLine("new picture dimensions {0}x{1}", mvarPicture.Width, mvarPicture.Height);
|
||||
|
||||
Image image = mvarPicture.ToImage();
|
||||
e.Graphics.DrawImage(image, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,17 +37,21 @@ namespace UniversalEditor.Plugins.Multimedia.UserInterface
|
||||
/// <param name="pic">The <see cref="PictureObjectModel" /> containing the image data to convert.</param>
|
||||
public static Image ToImage(this PictureObjectModel pic)
|
||||
{
|
||||
Image image = Image.Create(pic.Width, pic.Height);
|
||||
Graphics g = Graphics.FromImage(image);
|
||||
|
||||
for (int x = 0; x < pic.Width; x++)
|
||||
byte[] input = pic.ToByteArray();
|
||||
byte[] output = new byte[input.Length];
|
||||
for (int i = 0; i < input.Length; i += 4)
|
||||
{
|
||||
for (int y = 0; y < pic.Height; y++)
|
||||
{
|
||||
Color c = pic.GetPixel(x, y);
|
||||
g.DrawLine(new Pen(c), x, y, x + 1, y + 1);
|
||||
}
|
||||
byte b = input[i];
|
||||
byte g = input[i + 1];
|
||||
byte r = input[i + 2];
|
||||
byte a = input[i + 3];
|
||||
|
||||
output[i] = r;
|
||||
output[i + 1] = g;
|
||||
output[i + 2] = b;
|
||||
output[i + 3] = a;
|
||||
}
|
||||
Image image = Image.FromBytes(output, pic.Width, pic.Height, pic.Stride);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,6 +37,20 @@ namespace UniversalEditor.ObjectModels.Multimedia.Picture
|
||||
|
||||
private PositionVector2 lastAddedLocation = new PositionVector2(0, 0);
|
||||
|
||||
public int Stride
|
||||
{
|
||||
get
|
||||
{
|
||||
// thanks https://stackoverflow.com/questions/2185944/why-must-stride-in-the-system-drawing-bitmap-constructor-be-a-multiple-of-4
|
||||
|
||||
// this calculation is CORRECT (at least on gdkpixbuf) so ***DON'T TOUCH IT***
|
||||
int bitsPerPixel = 32; // ((int)format & 0xff00) >> 8;
|
||||
int bytesPerPixel = 4; // (bitsPerPixel + 7) / 8; // wtf???
|
||||
int stride = 4 * ((Width * bytesPerPixel + 3) / 4);
|
||||
return stride;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Color> ColorMap { get; } = new List<Color>();
|
||||
|
||||
public void SetPixel(Color color)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user