Home > Back-end > About the bitmap and Canvas replication failure problem
About the bitmap and Canvas replication failure problem
Time:10-02
Hello everyone, I am now doing a program that need to copy a part of the already created good btimap to another bitmap, and save as JPG file images, but in the process of user actual use, duplicate failure will have a chance, which preserved the JPG is white picture phenomenon, I tested the code, found that the risk is very big, use bitblt also occur, both bitmap and Canvas will appear this kind of phenomenon: -- -- -- -- -- -- -- -- -- -- -- -- code -- -- -- -- -- -- -- -- -- -- -- -- Tempbit:=tbitmap. Create; Tempbit. Width:=332; Tempbit. Height:=212; Bmp2Jpg (sbeijing, GetMySelfPath + 'photo \ temp \ temp. JPG "); ,0,332,212 tempbit. Canvas. CopyRect (the Rect (0), sbeijing. The Canvas, the Rect (0,0,332,212)); tempbit1:=TBitmap. Create; Tempbit1. Width:=sbeijing. Width; Tempbit1. Height:=sbeijing. Height; Tempbit1. Canvas. CopyRec (tempbit1. Canvas. ClipRect, sbeijing. Canvas, sbeijing. Canvas. The ClipRect); Tempbit1. SaveToFile (GetMySelfPath + 'photo \ temp \ temp1. BMP'); Tempbit. SaveToFile (GetMySelfPath + 'photo \ temp \ temp. BMP'); Bmp2Jpg (tempbit PhotoRoot); BitBlt (tempbit. Handle, 0, 0, tempbit. Width, tempbit. Height, sbeijing. Handle, 0, 0, SRCCOPY); Tempbit. SaveToFile (GetMySelfPath + 'photo \ temp \ temp2. BMP'); TEMPBIT. Free; -- -- -- -- -- -- -- -- -- -- -- -- code -- -- -- -- -- -- -- -- -- -- -- -- Code above the red part of the increase test for me, want to have a look at the abnormal, various bitmap is generated correctly, found an exception occurs sbeijing keep temp. BMP can generate normal, other save pictures are all blank, I suspect the copyrect when abnormal happens, but I used to do C/C + + is also used when bitblt didn't happen this kind of phenomenon, the photo copy frequency is very high, also does not have this kind of phenomenon, Delphi is new to the development of language, especially where there is a problem? Pixel format or other?
CodePudding user response:
Look at your code, the first confirmed sbeijing. Bitmap images? Sbeijing is what east east? The Bmp2Jpg (sbeijing, GetMySelfPath + 'photo \ temp \ temp. JPG "); What did the concrete execution? Tempbit:=tbitmap. Create; Tempbit. Width:=332; Tempbit. Height:=212; Bmp2Jpg (sbeijing, GetMySelfPath + 'photo \ temp \ temp. JPG "); ,0,332,212 tempbit. Canvas. CopyRect (the Rect (0), sbeijing. The Canvas, the Rect (0,0,332,212));