Gdip image save intptr directly to my local disk

I have this code to get the image file from the scanner and save it to a local drive:

IntPtr img = (IntPtr)pics[i]; SetStyle(ControlStyles.DoubleBuffer, false); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.Opaque, true); SetStyle(ControlStyles.ResizeRedraw, true); SetStyle(ControlStyles.UserPaint, true); bmprect = new Rectangle(0, 0, 0, 0); bmpptr = GlobalLock(img); pixptr = GetPixelInfo(bmpptr); Gdip.SaveDIBAs(@"C:\", bmpptr, pixptr); 

The problem here is Gdip.SaveDIBAs(@"C:\", bmpptr, pixptr); . save dialog. enter image description here

I want to cancel this dialog box and save the file directly to my disk.

 **Updated:** public static bool SaveDIBAs(string picname, IntPtr bminfo, IntPtr pixdat) { SaveFileDialog sd = new SaveFileDialog(); sd.FileName = picname; sd.Title = "Save bitmap as..."; sd.Filter = "Bitmap file (*.bmp)|*.bmp|TIFF file (*.tif)|*.tif|JPEG file (*.jpg)|*.jpg|PNG file (*.png)|*.png|GIF file (*.gif)|*.gif|All files (*.*)|*.*"; sd.FilterIndex = 1; return true; } for (int i = 0; i < pics.Count; i++) { IntPtr img = (IntPtr)pics[i]; SetStyle(ControlStyles.DoubleBuffer, false); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.Opaque, true); SetStyle(ControlStyles.ResizeRedraw, true); SetStyle(ControlStyles.UserPaint, true); bmprect = new Rectangle(0, 0, 0, 0); bmpptr = GlobalLock(img); pixptr = GetPixelInfo(bmpptr); SaveDIBAs(@"C:\a.jpg", bmpptr, pixptr); } 
+7
c # image intptr scanning
source share
1 answer

I think you just need to just use the built-in Image and Bitmap types instead of directly calling the gdip.dll functions.

 IntPtr img = (IntPtr)pics[i]; using (Bitmap bmp = Image.FromHBitmap(img)) { bmp.Save(@"C:\a.jpg", ImageFormat.Jpeg); } 
0
source share

All Articles