If the image is in bmp format you can manipulate the resolutionsettings in the file so that the image will be scaled to fit the controll.
I have created a table that holds images that I wish to link to documents in the system. On the Sales Order form for instance I show an image that's imported and linked to the sales order by document no and document type.
Field No. Field Name Data Type Length Description
1 Document Type Option
2 Document No. Code 20
3 Data BLOB
4 Original Path Text 250
5 Resolusion Integer
In this table I hav some functions for scaling the images.
fnZoomFit(iWidth:Integer;iHeight:Integer) OK: Boolean
// Write image-blob to temp file
CALCFIELDS(Data);
// If unable to export to temp file
IF Data.EXPORT(ENVIRON('TEMP')+'\temp_img.bmp',FALSE) = '' THEN
EXIT(FALSE);
// Change resolusion
TempFile.TEXTMODE(FALSE);
TempFile.WRITEMODE(TRUE);
// If unable to open temp file
IF NOT TempFile.OPEN(ENVIRON('TEMP')+'\temp_img.bmp') THEN
EXIT(FALSE);
// Get resolusion
TempFile.SEEK(18);
IF TempFile.READ(iHorrizRes) = 0 THEN
EXIT(FALSE);
TempFile.SEEK(22);
IF TempFile.READ(iVertRes) = 0 THEN
EXIT(FALSE);
// If the image is too large for the controll
IF fnMax(fnInt((100000 * iHorrizRes) / iWidth),
fnInt((100000 * iVertRes) / iHeight) ) > 65000 THEN
EXIT(FALSE);
Resolusion := fnMax(fnInt((100000 * iHorrizRes) / iWidth),
fnInt((100000 * iVertRes) / iHeight) );
// Write new DPI
TempFile.SEEK(38);
TempFile.WRITE(Resolusion);
TempFile.SEEK(42);
TempFile.WRITE(Resolusion);
TempFile.CLOSE();
// Read back to image-blob
IF Data.IMPORT(ENVIRON('TEMP')+'\temp_img.bmp',FALSE) = '' THEN
EXIT(FALSE);
CALCFIELDS(Data);
EXIT(TRUE);
fnMax(i1 : Integer;i2 : Integer) iMax : Integer
IF i1 > i2 THEN
EXIT(i1)
ELSE
EXIT(i2);
fnInt(number : Decimal) int : Integer
EXIT(ROUND(number,1));
fnZoomImage(dZoomfactor : Decimal) ok : Boolean
IF (fnInt(Resolusion*dZoomfactor) <= 0) OR
(fnInt(Resolusion*dZoomfactor) > 65000) THEN
EXIT(FALSE);
// Write image-blob to temp file
CALCFIELDS(Data);
IF Data.EXPORT(ENVIRON('TEMP')+'\temp_img.bmp',FALSE) = '' THEN
EXIT(FALSE);
// Change resolusion
TempFile.TEXTMODE(FALSE);
TempFile.WRITEMODE(TRUE);
IF NOT TempFile.OPEN(ENVIRON('TEMP')+'\temp_img.bmp') THEN
EXIT(FALSE);
// Write new DPI
TempFile.SEEK(38);
TempFile.WRITE(fnInt(Resolusion*dZoomfactor));
TempFile.SEEK(42);
TempFile.WRITE(fnInt(Resolusion*dZoomfactor));
TempFile.CLOSE();
// Read back to image-blob
IF Data.IMPORT(ENVIRON('TEMP')+'\temp_img.bmp',FALSE) = '' THEN
EXIT(FALSE);
CALCFIELDS(Data);
Resolusion := fnInt(Resolusion*dZoomfactor);
IF Rec.Picture.HASVALUE THEN BEGIN
IF EXISTS('C:\sample1.BMP') THEN ERASE ('C:\sample1.BMP');
CALCFIELDS(Picture);
Rec.Picture.EXPORT('C:\sample1.BMP');
END;
I've written the above code in the Form - OnAfterGetRecord() of the Item Card.
Comments
we should increase the picture box size accordingly..
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
I have created a table that holds images that I wish to link to documents in the system. On the Sales Order form for instance I show an image that's imported and linked to the sales order by document no and document type.
Field No. Field Name Data Type Length Description
1 Document Type Option
2 Document No. Code 20
3 Data BLOB
4 Original Path Text 250
5 Resolusion Integer
In this table I hav some functions for scaling the images.
I'm getting the error message :
You connot use the file C:\sample1.BMP because it is alredy in use
from the following Codecolor=#BF0040]Red Marked[/color :
I've written the above code in the Form - OnAfterGetRecord() of the Item Card.
What is the reason behind that ? Kindly reply.