Quantcast
Channel: WriteableBitmapEx
Viewing all 360 articles
Browse latest View live

New Post: WinRT Blit image quality

$
0
0
This should actually work. Double check the coordinates and maybe try a different BlendMode like Alpha just to rule out this is not the issue.

New Post: WinRT Blit image quality

$
0
0
Thanks for your reply. Indeed there has been a coordinate issue. :-/ The rects are (horizontal start point, vertical start point, width, height) instead of (horizontal start, vertical start, horizontal end, vertical end). It would be nice if the documentation can be updated.

So it has to be:
dest.DrawInto(backgroundImage, xDestOffset, yDestOffset, 0, 0, backgroundImage.PixelWidth, backgroundImage.PixelHeight);

 public static void DrawInto(this WriteableBitmap dest, WriteableBitmap backgroundImage, int xDestOffset, int yDestOffset, int xstart, int ystart, int xend, int yend)
{
  Rect destRect = new Windows.Foundation.Rect(xDestOffset, yDestOffset, xend-xstart, yend-ystart);
  Rect srcRect = new Windows.Foundation.Rect(xstart, ystart, xend - xstart, yend - ystart);
  dest.Blit(destRect, backgroundImage, srcRect, WriteableBitmapExtensions.BlendMode.None);
 }

New Post: No alpha blending in the FillXXX methods

$
0
0
It works!
when this function will be commited on the repository?

New Post: No alpha blending in the FillXXX methods

$
0
0
It works, but it is not 100% precise, in my opinion, since the alpha channel should work on 256 values, not 255.
Suppose you choose a 128 value for your alpha component. It should mean that you'd like to compose evenly your color with what already there, but this algorithm will have it providing 127/255 part of the color against 128/255 of the other. Then you assign the complementary alpha each cycle of the loop, not a big issue, but optimizable.

I changed all fill extensions this way:

As soon as possible:
            int alpha = 1 + (int)((uint)color >> 24);
            if (alpha == 1) return;
Then, before the cycle:
            int alphac = 256 - alpha, p, pal, par, pag, pab;
            if (alphac > 0)
            {
                color &= 0xffffff;
                par = alpha * ((color >> 16) & 255);
                pag = alpha * ((color >> 8) & 255);
                pab = alpha * (color & 255);
                color = ((par >> 8) << 16)
                    | ((pag >> 8) << 8)
                    | (pab >> 8);
            }
In the cycle:
                                p = pixels[offset];
                                pal = 1 + (p >> 24);
                                par = alphac * pal * ((p >> 16) & 255);
                                pag = alphac * pal * ((p >> 8) & 255);
                                pab = alphac * pal * (p & 255);
                                pixels[offset] = (Math.Min(255, alpha + pal - 1) << 24)
                                    | (par & (255 * 256 * 256))
                                    | (pag & (255 * 256 * 256)) >> 8
                                    | (pab >> 16) + color;
If I'm right, the compiler will optimize the 255256256 to its equivalent, but some people find it more understandable.

New Post: What are the parameters for DrawCurve?

$
0
0
This is probably the easiest question in the world, since it will probably be in the documentation when it comes out, but I want to know what the parameters for the DrawCurve method are. The color parameter is obvious, but the points() and tension parameters I am not sure. With all the strange ways that arcs and circles can be specified, and with parameter names as general as points and unusual as tension, the names themselves are not enough to tell me what values I need. Can you give me a basic description of how to use DrawCurve? Thanks.

New Post: blit out of memory exception

$
0
0
I have one really large writeablebitmap and then I copy 33 small writeablebitmaps with function blit into the large one. For loading small bitmaps I use this function..
            BitmapImage img = new BitmapImage();
            img.CreateOptions = BitmapCreateOptions.None;
            Stream s = Application.GetResourceStream(new Uri(path, UriKind.Relative)).Stream;
            img.SetSource(s);

            Image = new WriteableBitmap(img);

            img = null;
            s.Dispose();
            GC.Collect();
For example after 15 writeablebitmaps that were loaded I get error Out of memory exception, because the large writeablebitmap ate all memory. What I would like to do is to store writeablebitmap into the Image and then to use garbage collector to release memory for next image. This code didn't work. Can you explain how it works this function?

New Post: No alpha blending in the FillXXX methods

$
0
0
I have tested your code but not blend correctly,
  public static void FillRectangleBlend2(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, Color colore)
  {
      var color = ConvertColor(colore);
      using (var context = bmp.GetBitmapContext())
      {
          // Use refs for faster access (really important!) speeds up a lot!
          var w = context.Width;
          var h = context.Height;
          var pixels = context.Pixels;

          // 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; }

          int alpha = 1 + (int)((uint)color >> 24);
          if (alpha == 1) return;

          int alphac = 256 - alpha, p, pal, par, pag, pab;
          if (alphac > 0)
          {
              color &= 0xffffff;
              par = alpha * ((color >> 16) & 255);
              pag = alpha * ((color >> 8) & 255);
              pab = alpha * (color & 255);
              color = ((par >> 8) << 16)
                  | ((pag >> 8) << 8)
                  | (pab >> 8);
          }

          unchecked
          {
              for (int y = y1; y <= y2; y++)
              {
                  for (int i = y * w + x1; i < y * w + x2; i++)
                  {
                      p = pixels[i];
                      pal = 1 + (p >> 24);
                      par = alphac * pal * ((p >> 16) & 255);
                      pag = alphac * pal * ((p >> 8) & 255);
                      pab = alphac * pal * (p & 255);
                      pixels[i] = (Math.Min(255, alpha + pal - 1) << 24)
                          | (par & (255 * 256 * 256))
                          | (pag & (255 * 256 * 256)) >> 8
                          | (pab >> 16) + color;

                  }
              }
          }

      }
  }

New Post: Win8.1 Blit Transparent Ink

$
0
0
I'm working on an app where the user is "marking up" an underlying image with the Ink API. One of the ink types is a Highlight tool. When I blit the ink strokes and background image together the transparency is lost leading to what was highlighted in the background image being completely blocked out. Here is what my code looks like any ideas how to preserve the transparency?
Thanks,
Chris
var backgroundBmp = await BitmapFactory.New(1, 1).FromStream(await file.OpenAsync(FileAccessMode.Read), Windows.Graphics.Imaging.BitmapPixelFormat.Unknown);
                
WriteableBitmap foregroundBmp;
using (InMemoryRandomAccessStream a = new InMemoryRandomAccessStream())
 {
   await inkManager.SaveAsync(a);
   a.Seek(0);
   foregroundBmp = await new WriteableBitmap(1, 1).FromStream(a, Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8);
  }
backgroundBmp.Blit(new Rect(inkManager.BoundingRect.X, inkManager.BoundingRect.Y, foregroundBmp.PixelWidth, foregroundBmp.PixelHeight),
                    foregroundBmp, new Rect(0,0, foregroundBmp.PixelWidth, foregroundBmp.PixelHeight),
                    WriteableBitmapExtensions.BlendMode.Alpha);

New Post: Visual Studio Express 2013

$
0
0
Hi all,

use this lib fine, the app with the library seems to work as expected when compiled. the only issue is with Visual Studio Express 2013 that i'm using. Error list shows lots of errors at places that i'm using the extension.

eg.
Error   5   'Windows.UI.Xaml.Media.Imaging.WriteableBitmap' does not contain a definition for 'Crop' and no extension method 'Crop' accepting a first argument of type 'Windows.UI.Xaml.Media.Imaging.WriteableBitmap' could be found (are you missing a using directive or an assembly reference?)
Error   2   'Windows.UI.Xaml.Media.Imaging.WriteableBitmap' does not contain a definition for 'RotateFree' and no extension method 'RotateFree' accepting a first argument of type 'Windows.UI.Xaml.Media.Imaging.WriteableBitmap' could be found (are you missing a using directive or an assembly reference?)
There's lots of 'em, at all places where the extension is used. i must have been missing something in the code or Visual Studio setting.

help anyone?

New Post: Get Thumbnail image aspect ratio

$
0
0
Hello,
i have a jpg file saved in a isolated storage.
I would a thumbnail (200x200) from this jpeg keep aspect ratio

this is a my code
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        WriteableBitmap wb = BitmapFactory.New(0, 0);
                        wb.FromStream(isolatedStorage.OpenFile("1.jpg", FileMode.Open, FileAccess.Read));

                        IsolatedStorageFileStream fileStream= isolatedStorage.CreateFile("1_thumb.jpg");

                        float aspectRatio = (float)wb.PixelWidth / wb.PixelHeight;

                        wb.SaveJpeg(fileStream, 200, (int) (200 / aspectRatio), 0, 100);

                        fileStream.Close();
                        wb = null;

                    }
it is correct?

wb.PixelWidth and wb.PixelHeight is 0!!

thank you

New Post: Win8.1 Blit Transparent Ink

$
0
0
Dear,
i have the same problem when i Blit for scrolling purpose the bitmap and the new bitmap lost the trasparency (it's painted white on background)
I'm using the wrong calling method?
     public void Blit(int pixelToBlit)
    {
         Rect s = new Rect(pixelToBlit, 0, wBitmap.Width, wBitmap.Height);
         Rect d = new Rect(0, 0, wBitmap.Width - pixelToBlit, wBitmap.Height);


        wBitmap.Blit(d, wBitmap, s, System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.None);
        this.Source = wBitmap;
 }

New Post: Invalidate not present in WPF

$
0
0
with the following code
        wbmp = BitmapFactory.New(300, 300);
        IMG1.Source = wbmp;
        BitmapContext bmpc = wbmp.GetBitmapContext();

        // Clear the WriteableBitmap with white color
        wbmp.Clear(Colors.Red);

        wbmp.DrawLine(0, 0, 1000, 1000, Colors.Black);
I can't see nothing on screen and Invalidate is not present in WPF. How can I use the library on FPF?

Best regards

New Post: Invalidate not present in WPF

$
0
0
You would need to dispose the context. In WPF the bitmap is invalidated when its unlocked. In WBX the this is done in the dispose call. Use it like this:
        wbmp = BitmapFactory.New(300, 300);
        IMG1.Source = wbmp;
        using(BitmapContext bmpc = wbmp.GetBitmapContext())
        {
            // Clear the WriteableBitmap with white color
            wbmp.Clear(Colors.Red);

            wbmp.DrawLine(0, 0, 1000, 1000, Colors.Black);
        }

New Post: Blur an Image on windows phone

$
0
0
This code doesn't work
Uri uri = new Uri(AnyUri, UriKind.RelativeOrAbsolute);
BitmapImage img1 = new BitmapImage();
img1.UriSource = uri;
img1.CreateOptions = BitmapCreateOptions.None;
WriteableBitmap wbm = new WriteableBitmap(img1);
var wbm2 = WriteableBitmapExtensions.Convolute(wbm, WriteableBitmapExtensions.KernelGaussianBlur5x5);
PanoramaBackground.ImageSource = wbm2;
It throws an exception of "Object reference not set to an instance of an object" at the line
WriteableBitmap wbm = new WriteableBitmap(img1);
Why ??

New Post: Use in Windows phone 8/8.1

$
0
0
Hi Currently within a Windows phone 8 app I generate a live tile as a JPG. Work fine and is okay in the limited memory allowed within the background agent.
But I now need to generate as PNG (transparent tiles for 8.1) and I have tried the ToolstackPNGwriter which works nicely well but simply uses to much memory for the BackgroundAgent.

Looking to see if I can use the WriteableBitmapEx and I see on the homepage here that there is a away to include the minimum possible by just including the relevant extension methods.
(I don't need the drawing functionality - simply want to saev to a PNG rather than a JPG

Looking for advice as to what/how to include the minimum possible, for this.

And hoping that it will be fine memory wise in the Background Agent!
  • thanks

New Post: Use in Windows phone 8/8.1

New Post: WritableBitmap with wrong colors

$
0
0
Hi,

I am using BitmapFactory to load a PNG from a file:
WriteableBitmap image = await BitmapFactory.New(1, 1).FromContent(new Uri("ms-appx:///Assets/image.png"));
When I display this image the colors are not correct. I have tried using different BitmapPixelFormat values but I always get the same result.

On the other hand, if I load the image into a BitmapImage object like this:
BitmapImage bitmapImage = new BitmapImage(new Uri("ms-appx:///Assets/image.png"));
the image is displayed correctly. Am I doing something wrong with WriteableBitmap?

Thanks!
Carlos.

New Post: Invalidate not present in WPF

$
0
0
teichgraf wrote:
You would need to dispose the context. In WPF the bitmap is invalidated when its unlocked. In WBX the this is done in the dispose call. Use it like this:
        wbmp = BitmapFactory.New(300, 300);
        IMG1.Source = wbmp;
        using(BitmapContext bmpc = wbmp.GetBitmapContext())
        {
            // Clear the WriteableBitmap with white color
            wbmp.Clear(Colors.Red);

            wbmp.DrawLine(0, 0, 1000, 1000, Colors.Black);
        }
I don't think it's needed to manually create the context.
Because a context will be created and disposed in DrawLine function refer to WriteableBitmapEx source code.

New Post: Invalidate not present in WPF

$
0
0
It's recommended to manually create the BitmapContext if you are performing more than one call inside it and if you have a batch of draw calls. You will see a huge performance change since Invalidate is only called once instead of n times.

New Post: ColorMatrix with WriteableBitmapEx

$
0
0
Hi everybody,

I would like to use WriteableBitmapEx in order to use a color Matrix just the one described here...

How can I do??

Thanks a lot!

Jymmy097
Viewing all 360 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>