Can i create a Blur effect for BitmapImage that is supported in Wind 8.1 ? I am trying with the library but some methods are not supported. If yes how can i load a BitmapImage and apply the effect ?
↧
New Post: WriteableBitmapEx Windows 8.1 Blur effect
↧
New Post: WriteableBitmapEx Windows 8.1 Blur effect
Try:
var blurred = myWriteablebitmap.Convolute(WriteableBitmapExtensions.KernelGaussianBlur3x3);
Or for more blurringvar evenMoreBlurred = myWriteablebitmap.Convolute(WriteableBitmapExtensions.KernelGaussianBlur5x5);
↧
↧
New Post: ColorMatrix with WriteableBitmapEx
We don't have built-in support for this. But you can look at the Convolute extension method and see how to iterate over the pixels. Applying a matrix should then be rather easy by implementing your own logic for the transformation.
↧
New Post: WriteableBitmapEx Windows 8.1 Blur effect
And if i have an element of type Image , how can i set WriteableBitmap to this Image ?
I tried WriteableBitmap writeableBmp = eikona (where eikona is the name of ImageControl , but the types don't match)
I tried WriteableBitmap writeableBmp = eikona (where eikona is the name of ImageControl , but the types don't match)
↧
New Post: Apps for Office
Have you thought about using the APIs to apps for Office?
↧
↧
New Post: zoomming and panning in plotting software
hi.
as recommended here i used WriteableBitmapEx to plot about 100000 points on the screen. not all 100000 points are drawing at once but about 1000 points in 30 ms and the performance is very good. now i want to have zoom and pan for plots without resizing plots so only distance between plot changes.
what's the solution? is blit function help in this case? how to use it? any other idea?
with every zoom key and arrow key pressed i have to clear writablebitmap and redraw all of 100000 points in new positions at once and this is very heavy.
what is the best way for zooming and panning. is there a function?
should i use 3D camera on Image? how (code sample)?
thanks.
as recommended here i used WriteableBitmapEx to plot about 100000 points on the screen. not all 100000 points are drawing at once but about 1000 points in 30 ms and the performance is very good. now i want to have zoom and pan for plots without resizing plots so only distance between plot changes.
what's the solution? is blit function help in this case? how to use it? any other idea?
with every zoom key and arrow key pressed i have to clear writablebitmap and redraw all of 100000 points in new positions at once and this is very heavy.
what is the best way for zooming and panning. is there a function?
should i use 3D camera on Image? how (code sample)?
thanks.
↧
New Post: Colorize an image
I just want to colorize an image (get it all greenish or whatever color is set). I use code like this:
wb.ForEach((x, y, color) =>
{
HSVColor hsv = ColorHelper.RGBtoHSV(color);
hsv.H = baseColorHSV.H;
hsv.S = baseColorHSV.S;
return ColorHelper.HSVtoRGB(hsv);
});
But that's very slowwwww. Any faster way to do this?↧
New Post: Colorize an image
Check out the code of the ForEach and just implement it with your code but without the extra method call of the delegate. Also try to inline your RGB to HSV conversion and avoid the color struct transformation.
↧
New Post: WritableBitmap with wrong colors
I still haven't found a fix for that. Does anybody have any clue why this is happening? Do I need to post more information? I would appreciate any help...
Best,
Carlos.
Best,
Carlos.
↧
↧
New Post: Anti Alias DrawLineAa too strong and some usefull extensions
Dear,
i use the magnificent WritableBitmapEx for plotting software, i also notice the Anti Alias method make lines too big, the antialias is set to strong.
There's a method to produce a soft anti alias lines? or for modify the DrawLineAa method?
Thanks a lot
i attach my WritableBitmap extensions for WPF,
Rene can you incorporate into the next release ? IF is usefull
Thanks
i use the magnificent WritableBitmapEx for plotting software, i also notice the Anti Alias method make lines too big, the antialias is set to strong.
There's a method to produce a soft anti alias lines? or for modify the DrawLineAa method?
Thanks a lot
i attach my WritableBitmap extensions for WPF,
Rene can you incorporate into the next release ? IF is usefull
Thanks
public static int ConvertColor(Color color)
{
var a = color.A + 1;
var col = (color.A << 24)
| ((byte)((color.R * a) >> 8) << 16)
| ((byte)((color.G * a) >> 8) << 8)
| ((byte)((color.B * a) >> 8));
return col;
}
public static BitmapImage ToBitmapImage(this WriteableBitmap wbm)
{
BitmapImage bmImage = new BitmapImage();
using (MemoryStream stream = new MemoryStream())
{
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(wbm));
encoder.Save(stream);
bmImage.BeginInit();
bmImage.CacheOption = BitmapCacheOption.OnLoad;
bmImage.StreamSource = stream;
bmImage.EndInit();
bmImage.Freeze();
}
return bmImage;
}
public static WriteableBitmap Crop(this WriteableBitmap bmpSource, System.Drawing.Rectangle recSource)
{
int stride = bmpSource.PixelWidth * (bmpSource.Format.BitsPerPixel / 8);
byte[] data = new byte[stride * bmpSource.PixelHeight];
bmpSource.CopyPixels(data, stride, 0);
WriteableBitmap target = new WriteableBitmap(
bmpSource.PixelWidth,
bmpSource.PixelHeight,
bmpSource.DpiX, bmpSource.DpiY,
bmpSource.Format, null);
return bmpSource;
}
public static void FillRectangleBlend(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, System.Drawing.Color color)
{
using (var context = bmp.GetBitmapContext())
{
var w = context.Width;
var h = context.Height;
#endif
#if ANDROID
int[] pixels = new int[(int)(bmp.Width * bmp.Height)];
bmp.GetPixels(pixels, 0, bmp.Width, 0, 0, bmp.Width, bmp.Height);
#else
var pixels = context.Pixels;
#endif
// Check boundaries
if ((x1 < 0 && x2 < 0) || (y1 < 0 && y2 < 0)
|| (x1 >= w && x2 >= w) || (y1 >= h && y2 >= h))
{
return;
}
// Clamp boundaries
if (x1 < 0) { x1 = 0; }
if (y1 < 0) { y1 = 0; }
if (x2 < 0) { x2 = 0; }
if (y2 < 0) { y2 = 0; }
if (x1 >= w) { x1 = w - 1; }
if (y1 >= h) { y1 = h - 1; }
if (x2 >= w) { x2 = w - 1; }
if (y2 >= h) { y2 = h - 1; }
byte oneOverAlpha = (byte)(255 - color.A);
unchecked
{
for (int y = y1; y <= y2; y++)
{
for (int i = y * w + x1; i <= y * w + x2; i++)
{
int c = pixels[i];
int r = ((byte)(c >> 16) * oneOverAlpha + color.R * color.A) >> 8;
int g = ((byte)(c >> 8) * oneOverAlpha + color.G * color.A) >> 8;
int b = ((byte)(c >> 0) * oneOverAlpha + color.B * color.A) >> 8;
pixels[i] = 255 << 24 | r << 16 | g << 8 | b;
}
}
#if ANDROID
bmp.SetPixels(pixels, 0, bmp.Width, 0, 0, bmp.Width, bmp.Height);
#else
}
#endif
}
}
public static void FillRectangleDeBlend(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, Color color)
{
using (var context = bmp.GetBitmapContext())
{
// Use refs for faster access (really important!) speeds up a lot!
int w = bmp.PixelWidth;
int h = bmp.PixelHeight;
var pixels = context.Pixels;
// Check boundaries
if (x1 < 0) { x1 = 0; }
if (y1 < 0) { y1 = 0; }
if (x2 < 0) { x2 = 0; }
if (y2 < 0) { y2 = 0; }
if (x1 >= w) { x1 = w - 1; }
if (y1 >= h) { y1 = h - 1; }
if (x2 >= w) { x2 = w - 1; }
if (y2 >= h) { y2 = h - 1; }
byte oneOverAlpha = (byte)(255 - color.A);
unchecked
{
for (int y = y1; y <= y2; y++)
{
for (int i = y * w + x1; i <= y * w + x2; i++)
{
int c = pixels[i];
int r = (((byte)(c >> 16) << 8) / oneOverAlpha);
int g = (((byte)(c >> 8) << 8) / oneOverAlpha);
int b = (((byte)(c >> 0) << 8) / oneOverAlpha);
pixels[i] = 255 << 24 | r << 16 | g << 8 | b;
}
}
}
}
}
↧
New Post: ToByteArray returns all zeros
I have the following code for a WinRT project:
However, The Bytes array contains all zeros. I need the byte array to store the image in my program's database. It obviously isn't working.
Is there something I'm not understanding about 'ToByteArray'?
Async Function SetImage(imagestream As IRandomAccessStream, image As Image) As Task
Dim Bitmap As New BitmapImage
Dim Bytes As Byte()
' Note
Bitmap.SetSource(imagestream) ' I get the width and height of the image from this
Dim Wbm as WriteableBitmap = New WriteableBitmap(Bitmap.PixelWidth, Bitmap.PixelHeight)
image.Source = Await Wbm.FromStream(imagestream)
Bytes = Wbm.ToByteArray
End Function
The image appears correctly on-screen after this functionHowever, The Bytes array contains all zeros. I need the byte array to store the image in my program's database. It obviously isn't working.
Is there something I'm not understanding about 'ToByteArray'?
↧
New Post: ToByteArray returns all zeros
Update: I've determined that the problem lies with this line of code:
I tried converting the imagestream directly into a byte array and that at least produced 'something'. Which I could successfully save and the load from my database and the exact same 'thing' would reappear upon loading. Unfortunately, the image does not resemble in any way the actual image being loaded.
If someone can point me to a way to convert the imagestream into a proper byte array for WriteableBitmapEx I'd be home free. Otherwise if someone can help me figure out why reading from the stream isn't working that would do the trick too.
Thanks in advance for any help!
image.Source = Await Wbm.FromStream(imagestream)
Reading from the stream does not work. I've tried closing and reopening imagestream before reading, but that does not work either.I tried converting the imagestream directly into a byte array and that at least produced 'something'. Which I could successfully save and the load from my database and the exact same 'thing' would reappear upon loading. Unfortunately, the image does not resemble in any way the actual image being loaded.
If someone can point me to a way to convert the imagestream into a proper byte array for WriteableBitmapEx I'd be home free. Otherwise if someone can help me figure out why reading from the stream isn't working that would do the trick too.
Thanks in advance for any help!
↧
New Post: How to draw text in WPF without WriteableBitmap constructor that takes UIElement parameter?
(After giving up then coming back) I found some references that provided 2 key points regarding the RenderTargetBitmap object to avoid the memory leak and subsequent crash:
- Freeze() the object after Rendering the Visual (RenderTargetBitmap.Freeze())
-
Explicitly Clear (RenderTargetBitmap.Clear()) and null the object after blitting it
↧
↧
Commented Issue: I would like to draw arcs [18667]
I would like the ability in this library to draw arcs. Bresenham arc-drawing algorithms exist. See here:
http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
By arc, I mean a partial circle -- something with constructors very similar to the ArcSegment class in WPF. See here:
http://msdn.microsoft.com/en-us/library/ms589437.aspx
Thanks for your time.
Comments: ** Comment from web user: vac **
http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
By arc, I mean a partial circle -- something with constructors very similar to the ArcSegment class in WPF. See here:
http://msdn.microsoft.com/en-us/library/ms589437.aspx
Thanks for your time.
Comments: ** Comment from web user: vac **
I have also tried to draw arc with WritableBitmapExtension ( http://stackoverflow.com/questions/25392954/how-to-draw-an-arc-on-writablebitmap-writablebitmapex )
After analyzing code of mono libgdiplus I have ported two functions which are drawing arc using Bezier curve to c#.
I have attached result file.
It's using DrawBezier from WritableBitmapEx.
To draw an arc just use: .DrawArc(....);
ps. It would be nice to see it somewhere in WritableBitmapEx sources;
↧
Created Unassigned: IndexOutOfRangeException in System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLine(System.Windows.Media.Imaging.BitmapContext context, int pixelWidth, int pixelHeight, int x1, int y1, int x2, int y2, int color) [21266]
When the bitmap is large, you get this exception:
Here are the sample parameter values:
pixelWidth 4391
pixelHeight 5159
x1 1197
y1 3400
x2 1197
y2 3516
I believe the issue is due to this snippet:
int index = x1s + ((y1 * pixelWidth) << PRECISION_SHIFT);
// Walk the line!
var inc = (pixelWidth << PRECISION_SHIFT) + incx;
for (int y = y1; y <= y2; ++y)
{
pixels[index >> PRECISION_SHIFT] = color;
index += inc;
}
y1 * pixelWidth grows pretty fast, so after PRESIZION_SHIFT it overflows easily (in this case it was just making the number negative.
It probably should be modified to read:
int index = x1s;
int baseValue = (y1 * pixelWidth);
// Walk the line!
var inc = (pixelWidth << PRECISION_SHIFT) + incx;
for (int y = y1; y <= y2; ++y)
{
pixels[baseValue + (index >> PRECISION_SHIFT)] = color;
index += inc;
}
Here are the sample parameter values:
pixelWidth 4391
pixelHeight 5159
x1 1197
y1 3400
x2 1197
y2 3516
I believe the issue is due to this snippet:
int index = x1s + ((y1 * pixelWidth) << PRECISION_SHIFT);
// Walk the line!
var inc = (pixelWidth << PRECISION_SHIFT) + incx;
for (int y = y1; y <= y2; ++y)
{
pixels[index >> PRECISION_SHIFT] = color;
index += inc;
}
y1 * pixelWidth grows pretty fast, so after PRESIZION_SHIFT it overflows easily (in this case it was just making the number negative.
It probably should be modified to read:
int index = x1s;
int baseValue = (y1 * pixelWidth);
// Walk the line!
var inc = (pixelWidth << PRECISION_SHIFT) + incx;
for (int y = y1; y <= y2; ++y)
{
pixels[baseValue + (index >> PRECISION_SHIFT)] = color;
index += inc;
}
↧
Created Unassigned: Blit gives inconsistent results when enlarging [21275]
If I call Blit with a target rectangle that's exactly 3x the size of the source rectangle, I would expect the result to contain consistent, blocky, 3x3 "pixels". Instead, I get a crazy mishmash of 2x2, 2x3, 2x4, 3x2, 3x3, 3x4, 4x2, 4x3, and 4x4 "pixels" in the output.
Repro (using the latest NuGet package, 1.0.12.0):
var source = BitmapFactory.New(8, 8);
// Generate a checkerboard of pixels
for (var y = 0; y < source.Height; ++y)
for (var x = 0; x < source.Width; ++x)
source.SetPixel(x, y, ((x ^ y) & 1) == 1 ? Colors.Black : Colors.White);
// Enlarge to 3x
var target = BitmapFactory.New(source.PixelWidth * 3, source.PixelHeight * 3);
target.Blit(new Rect(0, 0, target.Width, target.Height), source,
new Rect(0, 0, source.Width, source.Height));
// Display the result
MyImage.Source = target;
Expected: a nice even checkerboard. Every square in the output should be 3 pixels wide and 3 pixels tall.
Actual: the row heights are 3, 4, 2, 3, 4, 3, 3, 2. Same kind of crazy variation on column widths. See attachment.
Repro (using the latest NuGet package, 1.0.12.0):
var source = BitmapFactory.New(8, 8);
// Generate a checkerboard of pixels
for (var y = 0; y < source.Height; ++y)
for (var x = 0; x < source.Width; ++x)
source.SetPixel(x, y, ((x ^ y) & 1) == 1 ? Colors.Black : Colors.White);
// Enlarge to 3x
var target = BitmapFactory.New(source.PixelWidth * 3, source.PixelHeight * 3);
target.Blit(new Rect(0, 0, target.Width, target.Height), source,
new Rect(0, 0, source.Width, source.Height));
// Display the result
MyImage.Source = target;
Expected: a nice even checkerboard. Every square in the output should be 3 pixels wide and 3 pixels tall.
Actual: the row heights are 3, 4, 2, 3, 4, 3, 3, 2. Same kind of crazy variation on column widths. See attachment.
↧
Created Unassigned: FillRectangle incorrectly includes right/bottom [21276]
If you call FillRectangle and pass a rectangle with width 1 and height 1, it instead fills an area 2 pixels wide and 2 pixels high.
It appears that WriteableBitmapEx's FillRectangle is including x2 and y2 in its rectangle. This is inconsistent with both System.Drawing and WPF, as well as every other graphics library I've ever used (GDI, GDI+, Delphi's TCanvas, ImageMagick, PyGame, etc.) FillRect calls typically do not fill the right-most column or the bottom-most row. That's because rectangle coordinates typically represent the grid lines between pixels, and that's because the math is far, far easier that way. (Raymond Chen has a good explanation at http://blogs.msdn.com/b/oldnewthing/archive/2004/02/18/75652.aspx.)
Repro:
var bitmap = BitmapFactory.New(2, 2);
// Should fill an area (1 - 0) pixels wide and (1 - 0) pixels high
bitmap.FillRectangle(0, 0, 1, 1, Colors.Red);
MyImage.Source = bitmap;
Expected: a 2x2 bitmap with one red pixel in the top left.
Actual: a 2x2 bitmap completely filled with red.
It appears that WriteableBitmapEx's FillRectangle is including x2 and y2 in its rectangle. This is inconsistent with both System.Drawing and WPF, as well as every other graphics library I've ever used (GDI, GDI+, Delphi's TCanvas, ImageMagick, PyGame, etc.) FillRect calls typically do not fill the right-most column or the bottom-most row. That's because rectangle coordinates typically represent the grid lines between pixels, and that's because the math is far, far easier that way. (Raymond Chen has a good explanation at http://blogs.msdn.com/b/oldnewthing/archive/2004/02/18/75652.aspx.)
Repro:
var bitmap = BitmapFactory.New(2, 2);
// Should fill an area (1 - 0) pixels wide and (1 - 0) pixels high
bitmap.FillRectangle(0, 0, 1, 1, Colors.Red);
MyImage.Source = bitmap;
Expected: a 2x2 bitmap with one red pixel in the top left.
Actual: a 2x2 bitmap completely filled with red.
↧
↧
Reviewed: WriteableBitmapEx 1.0.9 (Σεπ 26, 2014)
Rated 5 Stars (out of 5) - Very helpfull
A big thanks to all the delevelopers
↧
Reviewed: WriteableBitmapEx 1.0.9 (oct. 13, 2014)
Rated 5 Stars (out of 5) - Works like a charm. Simply needed to get and set individual pixels, and ended up here finding a treasure trove. Thanks for sharing your work and expertise.
↧
Source code checked in, #111026
* Commented out the Bitmapformat check
↧