Forum Replies Created
- AuthorPosts
- September 24, 2007 at 2:29 am in reply to: application memory and virtual memory increase quickly #24146
Hi Gabe, thanks very much, if i scan step by step handwork(the scan speed is slowly), the virtual memory and memory is released delay some minutes, i think may be the code is not any bug, if i scan by TestParter(testing tool, running script, scan speed is higher), the virtual memory and memory used speed higher than release speed, so appear phenomena memory and virtual memory more and more.
September 21, 2007 at 9:21 am in reply to: application memory and virtual memory increase quickly #24143Hi Geba, yes,i using the SetDIBitsToDevice method,but has release the object as coding segement:
protected Bitmap InptrToBitmap(IntPtr pixptr, IntPtr bmpptr)
{
Bitmap bitmap=new Bitmap(bmprect.Width,bmprect.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{IntPtr hdc = g.GetHdc();
SetDIBitsToDevice(hdc, bmprect.X, bmprect.Y, bmprect.Width, bmprect.Height,
bmprect.X, bmprect.Y, 0, bmprect.Height, pixptr, bmpptr, 0);
g.ReleaseHdc(hdc);
}
return bitmap;
}September 21, 2007 at 6:07 am in reply to: application memory and virtual memory increase quickly #24141Hi Gabe, thanks for your reply, yes, but i has use GlobalFree to release the handle, see my code segment. thanks again!
bool IMessageFilter.PreFilterMessage(ref Message m)
{
TwainCommand cmd = TwianScanner.PassMessage(ref m);
if (cmd == TwainCommand.Not)
return false;switch (cmd)
{
case TwainCommand.CloseRequest:
{
EndingScan();
TwianScanner.CloseSrc();
break;
}
case TwainCommand.CloseOk:
{
EndingScan();
TwianScanner.CloseSrc();
break;
}
case TwainCommand.DeviceEvent:
{
break;
}
case TwainCommand.TransferReady:
{ArrayList pics = TwianScanner.TransferPictures();
this.AutoScrollPosition = new Point(0, 0);
EndingScan();TwianScanner.CloseSrc();
m_nPicnumber++;
for (int i = 0; i < pics.Count; i++)
{
IntPtr imgPtr = (IntPtr)pics;IntPtr bmpptr = GlobalLock(imgPtr);
IntPtr pixptr = GetPixelInfo(bmpptr);this.AutoScrollPosition = new Point(0, 0);
if (m_bmpOrigin!=null)
{
m_bmpOrigin.Dispose();
}m_bmpOrigin = InptrToBitmap(pixptr, bmpptr);
Bitmap bmp = new Bitmap(m_bmpOrigin);if (m_bFullSize)
{
pictureBox.Width = bmp.Width;
pictureBox.Height = bmp.Height;}
else
{
pictureBox.Width = m_nPicOrgWidth;
pictureBox.Height = m_nPicOrgHeight;
bmp = new Bitmap(m_bmpOrigin, this.pictureBox.Width, this.pictureBox.Height);}
m_nRotate = 1;
pictureBox.Image = bmp;
if (imgPtr != null)
{
GlobalFree(imgPtr);
}if (bmpptr!=null)
{
GlobalFree(bmpptr);
}if (pixptr!=null)
{
GlobalFree(pixptr);
}}
if (pics!=null)
{
pics.Clear();}
break;
}
}return true;
} - AuthorPosts