About Resize Method

Mar 9, 2010 at 11:30 AM

hello

it's very useful project.

I want to resize images size before upload dut it seems that the resize method is not complete.

silverlight 3 don't have BitmapEncoder Class .

how to build the resize method?

thinks

forgive me,my english is poor

Coordinator
Mar 9, 2010 at 12:14 PM

I don't understand your problem exactly. Why BitmapEncoder? Do you want to compress the image after it was resized?

You can use the Resize method of theis library to resize a WriteableBitmap like this:

// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method
var resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);

Then encode the resized bitmap to a JPEG for example and send it to the server. JPEG encoding is not part of this library, but I wrote a blog post on how to do this with FJCore:

Mar 10, 2010 at 4:24 AM

Thank you .I will try it again.

Apr 8, 2010 at 8:19 AM

I also experienced the missing extension functions for Crop and Resize. They are not present in the DLL for WriteableBitmapEx_v0.9.0.0.

Please tell me if I overlooked anything, or that they are simpley missing.

 

Here is an overview of the functions inside the WriteableBitmapExtensions class (so you can see they are missing here):

public static class WriteableBitmapExtensions
    {
        public static void Blit(this WriteableBitmap bmp, Rect destRect, WriteableBitmap source, Rect sourceRect);
        public static void Blit(this WriteableBitmap bmp, Rect destRect, WriteableBitmap source, Rect sourceRect, WriteableBitmapExtensions.BlendMode BlendMode);
        public static void Blit(this WriteableBitmap bmp, Point destPosition, WriteableBitmap source, Rect sourceRect, Color color, WriteableBitmapExtensions.BlendMode BlendMode);
        public static void Blit(this WriteableBitmap bmp, Rect destRect, WriteableBitmap source, Rect sourceRect, Color color, WriteableBitmapExtensions.BlendMode BlendMode);
        public static void Clear(this WriteableBitmap bmp);
        public static void Clear(this WriteableBitmap bmp, Color color);
        public static WriteableBitmap Clone(this WriteableBitmap bmp);
        public static void DrawBezier(this WriteableBitmap bmp, int x1, int y1, int cx1, int cy1, int cx2, int cy2, int x2, int y2, Color color);
        public static void DrawBezier(this WriteableBitmap bmp, int x1, int y1, int cx1, int cy1, int cx2, int cy2, int x2, int y2, int color);
        public static void DrawBeziers(this WriteableBitmap bmp, int[] points, Color color);
        public static void DrawBeziers(this WriteableBitmap bmp, int[] points, int color);
        public static void DrawCurve(this WriteableBitmap bmp, int[] points, float tension, Color color);
        public static void DrawCurve(this WriteableBitmap bmp, int[] points, float tension, int color);
        public static void DrawEllipse(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, Color color);
        public static void DrawEllipse(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color);
        public static void DrawEllipseCentered(this WriteableBitmap bmp, int xc, int yc, int xr, int yr, Color color);
        public static void DrawEllipseCentered(this WriteableBitmap bmp, int xc, int yc, int xr, int yr, int color);
        public static void DrawLine(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, Color color);
        public static void DrawLine(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color);
        public static void DrawLine(int[] pixels, int pixelWidth, int pixelHeight, int x1, int y1, int x2, int y2, int color);
        public static void DrawLineBresenham(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, Color color);
        public static void DrawLineBresenham(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color);
        public static void DrawLineDDA(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, Color color);
        public static void DrawLineDDA(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color);
        public static void DrawPolyline(this WriteableBitmap bmp, int[] points, Color color);
        public static void DrawPolyline(this WriteableBitmap bmp, int[] points, int color);
        public static void DrawQuad(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, Color color);
        public static void DrawQuad(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int color);
        public static void DrawRectangle(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, Color color);
        public static void DrawRectangle(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color);
        public static void DrawTriangle(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int x3, int y3, Color color);
        public static void DrawTriangle(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int x3, int y3, int color);
        public static void ForEach(this WriteableBitmap bmp, Func<int, int, Color, Color> func);
        public static void ForEach(this WriteableBitmap bmp, Func<int, int, Color> func);
        public static void FromByteArray(this WriteableBitmap bmp, byte[] buffer);
        public static void FromByteArray(this WriteableBitmap bmp, byte[] buffer, int count);
        public static void FromByteArray(this WriteableBitmap bmp, byte[] buffer, int offset, int count);
        public static void SetPixel(this WriteableBitmap bmp, int x, int y, Color color);
        public static void SetPixel(this WriteableBitmap bmp, int x, int y, int color);
        public static void SetPixel(this WriteableBitmap bmp, int x, int y, byte a, Color color);
        public static void SetPixel(this WriteableBitmap bmp, int x, int y, byte r, byte g, byte b);
        public static void SetPixel(this WriteableBitmap bmp, int x, int y, byte a, byte r, byte g, byte b);
        public static void SetPixeli(this WriteableBitmap bmp, int index, Color color);
        public static void SetPixeli(this WriteableBitmap bmp, int index, int color);
        public static void SetPixeli(this WriteableBitmap bmp, int index, byte a, Color color);
        public static void SetPixeli(this WriteableBitmap bmp, int index, byte r, byte g, byte b);
        public static void SetPixeli(this WriteableBitmap bmp, int index, byte a, byte r, byte g, byte b);
        public static byte[] ToByteArray(this WriteableBitmap bmp);
        public static byte[] ToByteArray(this WriteableBitmap bmp, int count);
        public static byte[] ToByteArray(this WriteableBitmap bmp, int offset, int count);
        public static void WriteTga(this WriteableBitmap bmp, Stream destination);

        public enum BlendMode
        {
            AlphaBlend = 0,
            Additive = 1,
            Subtractive = 2,
            Mask = 3,
            Multiply = 4,
            None = 5,
        }
    }

Thankx,
Andries.

Coordinator
Apr 8, 2010 at 9:31 AM

Yep, they are not part of 0.9.0.0 but you can download the current source code and build your own version or just include the WriteableBitmapTransformationExtensions.cs file or wait a couple of weeks until I find time to implement the planned features (Fill) for 0.9.5.0 and release the binary. 

Apr 8, 2010 at 12:19 PM

Thank you for your quick answer.

I found the functionality inside the TransformationExtensions in the source project as you mentioned.