使用Delphi 6使用StretchDIBits处理条形码图像 - 输出中缺少条形线 [英] Processing Barcode image with Delphi 6 using StretchDIBits - Missing Bar lines in the output

查看:256
本文介绍了使用Delphi 6使用StretchDIBits处理条形码图像 - 输出中缺少条形线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是在Delphi 6中开发的。由于后台处理和大量数据(它消耗大约60MB - 120MB的物理内存),这是一个资源集成应用程序。该应用程序的一个功能是在进行某些处理后创建条形码图像。
如果用户继续生成条形码,那么至少十分之一的条形码中缺少一行。
我们在生成输出时有以下步骤:

My application is developed in Delphi 6. This is a resource intesive application due to background processing and large volume of data (It consumes around 60MB - 120MB of physical memory). One of the functionality of this application is to create barcode images after doing certain procesing. If user keeps on generating the Barcodes, then at least One out of Ten Barcode has missing lines in it. We have following steps in generating the output:


  1. 在内存中创建条形码图像(TImage)。图像的高度为10像素。我们使用pf24bit像素格式。

  2. 根据打印机的画布​​调整内存中的图像大小并将其传递到打印机的画布​​。
    步骤#2的代码如下:







procedure PrintBitmap(ARect:TRect; Bitmap:TBitmap);
var
  Info: PBitmapInfo;
  InfoSize: dword{Integer};
  Image: Pointer;
  ImageSize: dword{ integer};
  iReturn : integer ;
  iWidth,iHeight :integer;
begin
try
  with Bitmap do
  begin
     iReturn := 1;
     GetDIBSizes( Handle, InfoSize, ImageSize );
     GetMem( Info, InfoSize );
     try
        getMem( Image, ImageSize );
        try
           GetDIB(Handle, Palette, Info^, Image^);
           try
             with Info^.bmiHeader do
             begin
                SetStretchBltMode(Printer.Canvas.handle,HALFTONE);
                iReturn := **StretchDIBits**(Printer.Canvas.Handle, ARect.Left, ARect.Top,
                ARect.Right - ARect.Left, ARect.Bottom - ARect.Top,
                0, 0, biWidth, biHeight, Image, Info^, DIB_RGB_COLORS, SRCCOPY);
             end;
           except on E:Exception do
           begin
              gobjLog.pWritetoLog(0,'RptWrks2','PrintBitmap','Exception in StretchDIBits with message '+e.Message);
           end;
           end
        finally
           FreeMem(Image, ImageSize);
        end;
     finally
        FreeMem(Info, InfoSize);
     end;
end
except on E:Exception do
begin
    gobjLog.pWritetoLog(0,'RptWrks2','PrintBitmap','Exception in PrintBitMap with message '+e.Message);
end;

end;

我们检查问题出在第2步,因为条形码图像生成没有任何问题。 (我们注释了第2步并将输出作为BMP文件来确认这一点。)

We checked that the issue lies in the Step # 2 , as the barcode image is generated without any issue. (We commented out Step # 2 and took the output as BMP files to confirm this).

此外,我们尝试了以下解决方法:

Also, we tried following workarounds :


  1. 我们使用TExcellentImagePrinter组件来执行调整大小操作。但是,问题没有解决。

  2. 我们包含了SETPROCESSWORKINGSETSIZE WinAPI调用以减少/刷新应用程序使用的当前memry。

  3. 我们包括Sleep( 3000)在代码中,以便Windows能够为图像分配内存。但是包括睡眠可以降低出现此错误的频率。

您能提供任何建议吗?

推荐答案

最后我能够使用 TExcellentImagePrinter 解决问题。

Finally I was able to resolve the issue using TExcellentImagePrinter.

我用 LoadDIBFromTBitmap 函数和 StretchDIBits GETDIB 上面的代码片段(我的帖子)中的$ c> with PrintDIBitmapXY

I replaced GETDIB with LoadDIBFromTBitmap function and StretchDIBits with PrintDIBitmapXY in the above code snippet (my post).

感谢Joe提供正确的指导。

Thanks to Joe for providing proper guidelines.

这篇关于使用Delphi 6使用StretchDIBits处理条形码图像 - 输出中缺少条形线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆