bitmap - c# cut image in specific size in memory without save file -


i have colde :

 bitmap bmp = new bitmap(width, height); 

i take capture of window. want resize captured bitmap (bmp). how can cut bmp example

  rect rt = new rect();         getwindowrect(hwnd1, out rt);         int32 width = rt.right - rt.left;         int32 height = rt.bottom - rt.top;         int leftttt = rt.left + (width - 202);         int width2 = rt.right - leftttt;  //              // want cut : //       //  in x=lefttt  y = rt.top    size ( width2,height) 

and later can easy save file check results by: (but won't check)

    bmp.save(@"d:\test.jpg", imageformat.jpeg); 

edit: want cut not resize . when code :

var graph = graphics.fromimage(scren_kurwa.image);  graph.drawimage(bmp.image, 10, 10, 200, 200); 

and save override bmp screen , take capture in smaller version.

i want cut examaple want show 1/4 of width screen , save file. ( save 1/4 width not more).

edit 2 :

graph.copyfromscreen(leftttt, rt.top, 0, 0, new size(width2, height), copypixeloperation.sourcecopy); 

this code above doing want don't want again copy screen want copy bmp captured before.

please patient newbies . searched forums , can't find solution. thank you.

edit 3 did how wrote :

        rectangle croprect = new rectangle(100,100,100,100);         bitmap bmp1 = new bitmap(bmp1.image);         bmp1.clone(croprect, bmp.pixelformat);           bmp1.save(@"d:\xdddde.jpg", imageformat.jpeg); 

but don't cut image display same had bmp.

this should work you:

bitmap cuttedimage;  using(bitmap originalimage = new bitmap("filepathname")) {    rectangle croprect = new rectangle(...);     cuttedimage = originalimage .clone(croprect, originalbmp.pixelformat); }  cuttedimage.save("filepathname", imageformat.jpeg); cuttedimage.dispose(); 

note create shallow copy of bitmap. in case not seem problem, keep in mind.

also make sure check msdn documentation exception handling. either check rectangle bigger 0 , not bigger original image beforehand or catch exceptions.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -