Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:49:37+00:00 2026-05-16T17:49:37+00:00

I have created a WriteableBitmap in Gray16 format. I want to resize this WriteableBitmap

  • 0

I have created a WriteableBitmap in Gray16 format. I want to resize this WriteableBitmap to my known dimention preserving the pixel format(Gray16).

Is any one worked on the Resizing the WriteableBitmap. Please help me.

I also searched the internet and found http://writeablebitmapex.codeplex.com/ but this through an assebmly reference error.

Please help me.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:49:38+00:00Added an answer on May 16, 2026 at 5:49 pm

    I have written the function which resizes the writableBitmap. I have posted the code at my blog:

    http://harshaprojects.wordpress.com/2010/08/30/resize-writable-bitmap-in-wpf/

    hope it will be helpful.

    Code:

        using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using Microsoft.Win32;
    using System.IO;
    using System.Windows.Interop;
    namespace System.Windows.Media.Imaging
    {
    public static class RewritableBitmap
    {
    public static WriteableBitmap ResizeWritableBitmap(this WriteableBitmap wBitmap,int reqWidth, int reqHeight)
    {
    int Stride = wBitmap.PixelWidth * ((wBitmap.Format.BitsPerPixel + 7) / 8);
    int NumPixels = Stride * wBitmap.PixelHeight;
    ushort[] ArrayOfPixels = new ushort[NumPixels];
    
    
    wBitmap.CopyPixels(ArrayOfPixels, Stride, 0);
    
    int OriWidth = (int) wBitmap.PixelWidth;
    int OriHeight = (int) wBitmap.PixelHeight;
    
    double nXFactor = (double)OriWidth / (double)reqWidth;
    double nYFactor = (double)OriHeight / (double)reqHeight;
    
    double fraction_x, fraction_y, one_minus_x, one_minus_y;
    int ceil_x, ceil_y, floor_x, floor_y;
    
    ushort pix1, pix2, pix3, pix4;
    int nStride = reqWidth * ((wBitmap.Format.BitsPerPixel + 7) / 8);
    int nNumPixels = reqWidth * reqHeight;
    ushort[] newArrayOfPixels = new ushort[nNumPixels];
    /*Core Part*/
                /* Code project article :
    Image Processing for Dummies with C# and GDI+ Part 2 - Convolution Filters By Christian Graus</a>
    
                href=<a href="http://www.codeproject.com/KB/GDI-plus/csharpfilters.aspx"></a>
                */
                for (int y = 0; y < reqHeight; y++)
    {
    for (int x = 0; x < reqWidth; x++)
    {
    // Setup
    floor_x = (int)Math.Floor(x * nXFactor);
    floor_y = (int)Math.Floor(y * nYFactor);
    
    ceil_x = floor_x + 1;
    if (ceil_x >= OriWidth) ceil_x = floor_x;
    
    ceil_y = floor_y + 1;
    if (ceil_y >= OriHeight) ceil_y = floor_y;
    
    fraction_x = x * nXFactor - floor_x;
    fraction_y = y * nYFactor - floor_y;
    
    one_minus_x = 1.0 - fraction_x;
    one_minus_y = 1.0 - fraction_y;
    
    pix1 = ArrayOfPixels[floor_x + floor_y * OriWidth];
    pix2 = ArrayOfPixels[ceil_x + floor_y * OriWidth];
    pix3 = ArrayOfPixels[floor_x + ceil_y * OriWidth];
    pix4 = ArrayOfPixels[ceil_x + ceil_y * OriWidth];
    
    ushort g1 = (ushort)(one_minus_x * pix1 + fraction_x * pix2);
    ushort g2 = (ushort)(one_minus_x * pix3 + fraction_x * pix4);
    ushort g = (ushort)(one_minus_y * (double)(g1) + fraction_y * (double)(g2));
    newArrayOfPixels[y * reqWidth + x] = g;
    }
    }
               /*End of Core Part*/
    WriteableBitmap newWBitmap = new WriteableBitmap(reqWidth, reqHeight, 96, 96, PixelFormats.Gray16, null);
    Int32Rect Imagerect = new Int32Rect(0, 0, reqWidth, reqHeight);
    int newStride = reqWidth * ((PixelFormats.Gray16.BitsPerPixel + 7) / 8);
    newWBitmap.WritePixels(Imagerect, newArrayOfPixels, newStride, 0);
    return newWBitmap;
    }
    
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created one jsp file but it doesn't running in any way..!! it
I have created a SSRS 2008 report.I have created a matrix.I want to make
I have created a windows service which is set to start automatically. This service
I have created a NSCollectionViewItem subclass, called TSCollectionViewController . It overrides one method, setRepresentedObject:
I have created an Enum and want to read the text value from it.
I have created a QWidget with a bunch of QToolButtons in it and I
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have created some JQuery that will expand a div 'popup' on hover and
I have created a JSP / servlets application running in Tomcat 7. It runs
I have created an EDMX in visual studio 2010 SP1. It has been built

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.