c# - Turning These Two Image Manipulation Methods Into One? -


i have 2 methods exact same thing except 1 on bitmap , other on image. want able have 1 method it's cleaner, don't know how accomplish this. if it's not possible put these 2 methods together, best way simplify , condense of code?

thanks!

static private bitmap resizebitmap(bitmap inputbitmap, orientation orientation) {     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 (inputbitmap.width > pagewidth) {         scalex = convert.todouble(pagewidth) / convert.todouble(inputbitmap.width);         scaley = scalex;     }     if (inputbitmap.height * scaley > pageheight) {         scaley = scaley * convert.todouble(pageheight) / convert.todouble(inputbitmap.height);         scalex = scaley;     }     bitmap outputimage = new bitmap(convert.toint16(inputbitmap.width * scalex), convert.toint16(inputbitmap.height * scaley));     using (graphics g = graphics.fromimage(outputimage))          g.drawimage(inputbitmap, 0, 0, outputimage.width, outputimage.height);     return outputimage; } static private image resizeimage(image inputimage, orientation orientation) {     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 (inputimage.width > pagewidth) {         scalex = convert.todouble(pagewidth) / convert.todouble(inputimage.width);         scaley = scalex;     }     if (inputimage.height * scaley > pageheight) {         scaley = scaley * convert.todouble(pageheight) / convert.todouble(inputimage.height);         scalex = scaley;     }     bitmap outputimage = new bitmap(convert.toint16(inputimage.width * scalex), convert.toint16(inputimage.height * scaley));     using(graphics g = graphics.fromimage(outputimage))         g.drawimage(inputimage, 0, 0, outputimage.width, outputimage.height);     return outputimage; } 

you need single function takes image argument , has bitmap return type, since returning bitmap in resizeimage method. works since bitmap inherits image.

static private bitmap resizeimage(image inputimage, orientation orientation)  {     ... } 

this way don't have cast result of resizeimage if assigning variable of type bitmap (which assume original reason wrote both functions).


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -