c# 4.0 - how to write byte[] to Image with Landscape or Portrait properties? -


i have code converts byte[] image code writes in landscape mode original image portrait. how can detect original image's page orientation , write new image properties? suggestions?

public void sendfax(byte[] file, string filename)     {         try         {             memorystream ms = new memorystream(file);             image imgsave = image.fromstream(ms);             bitmap bmsave = new bitmap(imgsave);             bitmap bmtemp = new bitmap(bmsave);             graphics grsave = graphics.fromimage(bmtemp);             grsave.drawimage(imgsave, 0, 0, imgsave.width, imgsave.height)              //save image physical path             bmtemp.save("c:/..." + filename);              imgsave.dispose();             bmsave.dispose();             bmtemp.dispose();             grsave.dispose();          }         catch (exception ex)         {             throw ex;         }     } 

try this. check img height , width , based on comparison decide portrait/landscape

int srcwidth = image.width; int srcheight = image.height; int thumbwidth = width; int thumbheight; bitmap bmp; if (srcheight > srcwidth) {     thumbheight = (srcheight / srcwidth) * thumbwidth;     bmp = new bitmap(thumbwidth, thumbheight); } else {     thumbheight = thumbwidth;     thumbwidth = (srcwidth / srcheight) * thumbheight;     bmp = new bitmap(thumbwidth, thumbheight); } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -