c# - StretchBlt occasionally inverts image when it shouldn't -
i’m having problem using stretchblt (or bitblt) copy image picturebox bitmap use in creating avi file. avi file unimportant aspect believe - can display bitmap on picturebox , see problem.
the problem (not often) single image flipped (mirrored across x axis, never y axis). i’m not sure if known problem stretchblt haven’t yet found mention of or if doing wrong.
note not due intended functionality stretchblt of "if signs of source , destination height or width different creates mirror image".
update: changed things force source/destination same size, , using bitblt same behavior.
i’ve included code (c#), of important parts.
stepping through code can see happen single image has same information being passed stretchblt (other hdc copy to) previous image , next image (and next, next) of fine. doesn't happen often, , dont see reason when does. or way detect happened (so can flip back). have work around doesn't use stretchblt, slower , degrades performance.
another possibly useful bit: flipped image rare in normal usage (less 1 in 100 frames). when run in ide, stepping through image image, happens regularly (maybe 1 in 10).
any ideas causing or doing wrong? or other fast methods copy bitmap including re-sizing. note: bitmaps vary in size (can't use bitblt), not lot.
thank you!
kate
// --- import statement [dllimport("gdi32.dll", charset = charset.auto, setlasterror = true, exactspelling = true)] public static extern bool stretchblt( intptr hdcdest, int nxdest, int nydest, int ndestwidth, int ndestheight, intptr hdcsrc, int nxsrc, int nysrc, int nsrcwidth, int nsrcheight, int32 dwrop ); // --- small class creating/storing bitmap , graphics objects, reused public class caviimageinfo { private bitmap mavibitmap = null; private graphics mavigraphics = null; public caviimageinfo(int width, int height ) { mavibitmap = new bitmap(width, height); mavigraphics = graphics.fromimage(mavibitmap); } ~caviimageinfo() { mavigraphics.dispose(); mavigraphics = null; } public bitmap avibitmap { { return mavibitmap; } } public graphics avigraphics { { return mavigraphics; } } } // --- 2 pictureboxs placed on form @ design time (one watch these mirrored images): picturebox mmainpicturebox; // --- displays images copied picturebox debugpicturebox; // --- following done 1 time: graphics mmainpictureboxgraphics = mmainpicturebox.creategraphics(); intptr mmainpictureboxhdc = mmainpictureboxgraphics.gethdc(); // --- method copying. called each time image on panel updated. public void updateavirecording() { // --- gets unused bitmap , graphics objects (these reused) caviimageinfo aviimageinfo = getunusedaviimageinfo(); intptr destinationhdc = aviimageinfo.avigraphics.gethdc(); stretchblt( destinationhdc, 0, 0, aviimageinfo.avibitmap.width, aviimageinfo.avibitmap.height, mmainpictureboxhdc, 0, 0, mmainpicturebox.width, mmainpicturebox.height, srccopy); // --- show copied bitmap on debug picturebox // --- (normally pass written avi file) debugpicturebox.image = aviimageinfo.avibitmap; debugpicturebox.refresh(); aviimageinfo.avigraphics.releasehdc(destinationhdc); }
Comments
Post a Comment