Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In the general case, if you were dealing with two classes which have no common base class or interface (and you cannot add one), the best you can do is to pull out the code that is not dependent on the specific class into a new method that both of your existing methods call. For example, something like:</p> <pre><code>/// getNewDimensions static private void getNewDimensions(int ImageWidth, int ImageHeight, Orientation orientation, out int NewWidth, out int NewHeight) { double scaleX = 1; double scaleY = 1; int pageWidth = orientation == Orientation.Portrait ? (int)PageDimensions.Width : (int)PageDimensions.Height; int pageHeight = orientation == Orientation.Portrait ? (int)PageDimensions.Height : (int)PageDimensions.Width; if (ImageWidth &gt; pageWidth) { scaleX = Convert.ToDouble(pageWidth) / Convert.ToDouble(ImageWidth); scaleY = scaleX; } if (ImageHeight * scaleY &gt; pageHeight) { scaleY = scaleY * Convert.ToDouble(pageHeight) / Convert.ToDouble(ImageHeight); scaleX = scaleY; } NewWidth = ImageWidth * scaleX; NewHeight = ImageHeight * scaleY; } /// resizeBitmap static private Bitmap resizeBitmap(Bitmap inputBitmap, Orientation orientation) { int NewWidth = 0; int NewHeight = 0; getNewDimensions(inputBitmap.Width, inputBitmap.Width, orientation, NewWidth, NewHeight); Bitmap outputImage = new Bitmap(Convert.ToInt16(newWidth), Convert.ToInt16(newHeight)); using (Graphics g = Graphics.FromImage(outputImage)) g.DrawImage(inputBitmap, 0, 0, outputImage.Width, outputImage.Height); return outputImage; } /// resizeImage (I'll leave as an exercise to the reader) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload