本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.FromByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.FromByteArray方法的具体用法?C# WriteableBitmap.FromByteArray怎么用?C# WriteableBitmap.FromByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.FromByteArray方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Colorize
public static WriteableBitmap Colorize(WriteableBitmap b, int red, int green, int blue, ColorArea ca)
{
if (red < -255 || red > 255) throw new ArgumentException("Red must be between -255 and +255");
if (green < -255 || green > 255) throw new ArgumentException("Green must be between -255 and +255");
if (blue < -255 || blue > 255) throw new ArgumentException("Blue must be between -255 and +255");
int stride = b.PixelWidth * 4; //The pixelformat for brga32 is 32 bits - so that's 4 bytes per pixel
int bytes = Math.Abs(stride) * b.PixelHeight;
byte[] p = b.ToByteArray();
int i = 0;
int nOffset = stride - b.PixelWidth * 4;
for (int y = 0; y < b.PixelHeight; ++y)
{
for (int x = 0; x < b.PixelWidth; ++x)
{
int pdif = (p[i + 2] + p[i + 1] + p[i]) / 3;
int newred = p[i + 2];
int newgreen = p[i + 1];
int newblue = p[i];
switch (ca)
{
case ColorArea.Shadows:
float multi = (1 - newred / 255);
newred += (int)(red * multi);
multi = (1 - newgreen / 255);
newgreen += (int)(green * multi);
multi = (1 - newblue / 255);
newblue += (int)(blue * multi);
break;
case ColorArea.Highlights:
float hmulti = (newred / 255);
newred += (int)(red * hmulti);
hmulti = (newgreen / 255);
newgreen += (int)(green * hmulti);
hmulti = (newblue / 255);
newblue += (int)(blue * hmulti);
break;
case ColorArea.Midtones:
float mmulti = 0;
mmulti = (newred > 127) ? 127f / newred : newred / 127f;
newred += (int)(red * mmulti);
mmulti = (newgreen > 127) ? 127f / newgreen : newgreen / 127f;
newgreen += (int)(green * mmulti);
mmulti = (newblue > 127) ? 127f / newblue : newblue / 127f;
newblue += (int)(blue * mmulti);
break;
}
p[i + 2] = (byte)Math.Min(255, Math.Max(newred, 0));
p[i + 1] = (byte)Math.Min(255, Math.Max(newgreen, 0));
p[i + 0] = (byte)Math.Min(255, Math.Max(newblue, 0));
i += 4;
}
i += nOffset;
}
WriteableBitmap finalImg = new WriteableBitmap(b.PixelWidth, b.PixelHeight);
return finalImg.FromByteArray(p);
}
示例2: ColourImages
private void ColourImages()
{
BitmapImage vertical = new BitmapImage();
vertical.BeginInit();
vertical.UriSource = new Uri(@"images\BikeVertical.png", UriKind.Relative);
vertical.EndInit();
vert= new WriteableBitmap(vertical);
byte[] vData = vert.ToByteArray();
for (int i = 0; i < vData.Length; i= i + 4 )
{
if (vData[i] == 255 && vData[i + 1] == 255 && vData[i + 2] == 255)
{
vData[i] = ((SolidColorBrush)bikeColour).Color.B;
vData[i + 1] = ((SolidColorBrush)bikeColour).Color.G;
vData[i + 2] = ((SolidColorBrush)bikeColour).Color.R;
}
else if (vData[i] == 0xd4 && vData[i + 1] == 0xd4 && vData[i + 2] == 0xd4)
{
double scale = ((double)0xd4) / 0xFF;
vData[i] = (byte)(((SolidColorBrush)bikeColour).Color.B * scale);
vData[i + 1] = (byte)(((SolidColorBrush)bikeColour).Color.G * scale);
vData[i + 2] = (byte)(((SolidColorBrush)bikeColour).Color.R * scale);
}
}
vert.FromByteArray(vData);
BitmapImage horizontal = new BitmapImage();
horizontal.BeginInit();
horizontal.UriSource = new Uri(@"images\BikeHorizontal.png", UriKind.Relative);
horizontal.EndInit();
hor = new WriteableBitmap(horizontal);
byte[] hData = hor.ToByteArray();
for (int i = 0; i < hData.Length; i = i + 4)
{
if (hData[i] == 0xFF && hData[i + 1] == 0xFF && hData[i + 2] == 0xFF)
{
hData[i] = ((SolidColorBrush)bikeColour).Color.B;
hData[i + 1] = ((SolidColorBrush)bikeColour).Color.G;
hData[i + 2] = ((SolidColorBrush)bikeColour).Color.R;
}
else if (hData[i] == 0xd4 && hData[i + 1] == 0xd4 && hData[i + 2] == 0xd4)
{
double scale = ((double)0xd4) / 0xFF;
hData[i] = (byte)(((SolidColorBrush)bikeColour).Color.B*scale);
hData[i + 1] = (byte)(((SolidColorBrush)bikeColour).Color.G * scale);
hData[i + 2] = (byte)(((SolidColorBrush)bikeColour).Color.R * scale);
}
}
hor.FromByteArray(hData);
}
示例3: SCurve
public static WriteableBitmap SCurve(WriteableBitmap b)
{
int stride = b.PixelWidth * 4; //brga32 is 32
int bytes = Math.Abs(stride) * b.PixelHeight;
byte[] p = b.ToByteArray();
int i = 0;
int nOffset = stride - b.PixelWidth * 4;
Point[] points = GetCoordinates();
for (int y = 0; y < b.PixelHeight; ++y)
{
for (int x = 0; x < b.PixelWidth; ++x)
{
int hue = p[i]; //if pi = 255 then 255, otherwise -1 (so if pi = -1, its ! 255, NOT max)
int hue1 = p[i + 1];
int hue2 = p[i + 2];
foreach (var point in points)
{
if (hue != 255 && hue1 != 255 && hue2 != 255)
{
//white pixel - no processing necessary
break;
}
if (point.X >= p[i + 2] && hue2 != 255) //translate this to a function for the curve
hue2 = (int)point.Y;
if (point.X >= p[i + 1] && hue1 != 255)
hue1 = (int)point.Y;
if (point.X >= p[i] && hue != 255)
hue = (int)point.Y;
}
p[i + 2] = (byte)Math.Min(255, Math.Max(hue2, 0));
p[i + 1] = (byte)Math.Min(255, Math.Max(hue1, 0));
p[i + 0] = (byte)Math.Min(255, Math.Max(hue, 0));
i += 4;
}
i += nOffset;
}
WriteableBitmap finalImg = new WriteableBitmap(b.PixelWidth, b.PixelHeight);
return finalImg.FromByteArray(p);
//return true;
}
示例4: Contrast
public static WriteableBitmap Contrast(WriteableBitmap b, int nContrast)
{
if (nContrast < -100 || nContrast > 100)
{
throw new ArgumentException("Contrast must be between -100 and 100");
}
double contrast = (100.0 + nContrast) / 100.0;
contrast *= contrast;
int stride = b.PixelWidth * 4; //brga32 is 32
int bytes = Math.Abs(stride) * b.PixelHeight;
byte[] p = b.ToByteArray();
int i = 0;
int nOffset = stride - b.PixelWidth * 4;
for (int y = 0; y < b.PixelHeight; ++y)
{
for (int x = 0; x < b.PixelWidth; ++x)
{
p[i + 2] = ApplyContrast(p[i + 2], contrast);
p[i + 1] = ApplyContrast(p[i + 1], contrast);
p[i + 0] = ApplyContrast(p[i + 0], contrast);
i += 4;
}
i += nOffset;
}
WriteableBitmap finalImg = new WriteableBitmap(b.PixelWidth, b.PixelHeight);
return finalImg.FromByteArray(p);
}
示例5: loadFromImage
public void loadFromImage(object source)
{
if (source is string) {
if ((source = Moxie.comps.get((string)source, "Image")) == null) {
throw new ImageError(ImageError.WRONG_FORMAT);
}
}
Image image = (Image)source;
width = image.width;
height = image.height;
size = image.size;
type = image.type;
name = image.name;
meta = image.meta;
_bm = new WriteableBitmap(width, height);
_bm.FromByteArray(image.getAsByteArray());
Load(this, new DataEventArgs(getInfo()));
}
示例6: OnCreateAndUploadImage
public void OnCreateAndUploadImage(object obj)
{
EA.GetEvent<SetCompositionWidthHeight>().Publish(string.Empty);
var document = HtmlPage.Document;
var txtArea = document.GetElementById("MainContent_txtPNGBytes");
if (txtArea != null)
{
try
{
const double scale = 1;
var bmp = new WriteableBitmap(CompositionGrid, null);
var buffer = bmp.ToByteArray();
bmp = new WriteableBitmap(int.Parse(Width.ToString()), int.Parse(Height.ToString()));
bmp.FromByteArray(buffer);
var transform = new ScaleTransform();
transform.ScaleX = scale;
transform.ScaleY = scale;
bmp.Render(CompositionGrid, (Transform)transform);
bmp.Invalidate();
var stream = bmp.GetStream();
var binaryData = new Byte[stream.Length];
var bytesRead = stream.Read(binaryData, 0, (int)stream.Length);
var base64 = Convert.ToBase64String(binaryData, 0, binaryData.Length);
RawSize = base64.Length.ToString();
Message message = Composer.Messaging.Compression.Compress(base64);
base64 = message.Text;
CompressedSize = base64.Length.ToString();
txtArea.SetProperty("value", base64);
UploadDetailsVisibility = Visibility.Visible;
SendImage();
}
catch (Exception ex)
{
Exceptions.HandleException(ex, "Error in: OnCreateAndUploadImage");
}
}
}
示例7: loadFromImage
public void loadFromImage(object source)
{
if (source is string) {
if ((source = Moxie.compFactory.get((string)source)) == null) {
Error(this, new ErrorEventArgs(ImageError.WRONG_FORMAT));
return;
}
}
Image image = (Image)source;
width = image.width;
height = image.height;
size = image.size;
type = image.type;
name = image.name;
meta = image.meta;
_bm = new WriteableBitmap(width, height);
_bm.FromByteArray(image.getAsByteArray());
Load(this, null);
}