image scaling

jksjks Member Posts: 277
Hi all,

I have one picturebox in my report in which I am displaying one bitmap image. Currently the bitmap is scaled as 70x70 pixels. Now I want to scale it according to the size of the picturebox in which I display that image.

Note that image is generated by another application which is linked with my Navision database via ATL COM interface.

How can I map the size of controls in Navision so that my image gets scaled properly.

Please help.

Comments

  • kinekine Member Posts: 12,562
    You cannot do it directly in NAV. But you can use the Resolution (X and Y resolution - like 72 dpi, 360 dpi etc.) attributes which are part of the .bmp file. If this attribute is set correctly, NAV will resize the bitmap. You can do it in your ATL COM interface or you can save the bmp into file, change the attribute there and reimport it back and use it. There is the code for changing the DPI values in the BMP file:
    BMPFile.TEXTMODE := FALSE;
    BMPFile.WRITEMODE := TRUE;
    BMPFile.OPEN(FName);
    
    SetResolutionValue := DPIValue;
    
    //Write horizontal resolution
    BMPFile.SEEK(38);
    BMPFile.WRITE(SetResolutionValue);
    
    //Write vertical resolution
    BMPFile.SEEK(42);
    BMPFile.WRITE(SetResolutionValue);
    
    BMPFile.CLOSE;
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • jksjks Member Posts: 277
    But how can I decide to which resolution should I use based on the size of the control?

    And also, in the following code is 38 and 42 are fixed for a particular DPI value?
    //Write horizontal resolution
    BMPFile.SEEK(38);
    BMPFile.WRITE(SetResolutionValue);

    //Write vertical resolution
    BMPFile.SEEK(42);
    BMPFile.WRITE(SetResolutionValue);

    Thanks for any help.
  • kinekine Member Posts: 12,562
    38 and 42 are offsets of the DPI values in the BMP header. You cannot change that...

    The recalculation is just about math:

    the width and height of the Image control are in 0.01mm (width 100 = 1 mm). DPI is "Dots per Inch" (Dot=Pixel). Your picture have 70x70 pixels. It means, if you select DPI=70 for both axis, the picture will have size 1x1 inch on the report, it means (1 inch = 25,4mm) that it will fill picture box with size 2540x2540 in Nav. If I am right, you need to calculate the DPI as:

    DPI = (SizeOfImage/SizeInNav)*2540

    But there can be some deviation and you need to find correct proportion...

    And the value of SetResolutionValue is integer!
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • jksjks Member Posts: 277
    Hi Kine,

    Thanks for your help. Really a great help for me.
    Just to confirm, if I scale the image in a following way then will it give the same result as yours?

    Size of image control in Navision 113 * 100 mm
    PixelsX = 1024 = Width in pixel of the device
    PixelsY = 768 = Height in pixel of the device
    MMX = 320 = Width in mm of the device
    MMY = 240 = Height in mm of the device

    Set X and Y as follow:
    X = 113 * (1024/320)
    Y = 100 * (768/240)

    So my scaled image will be of X * Y pixels. Is this correct?

    Thanks for your great help.
  • kinekine Member Posts: 12,562
    From the values you can calculate that:

    The device have DPI = 82 in both axis (it is 81.27 but DPI is integer...). And now it depends on what you want to do. If you will calculate the X and Y, you will get pixel size for image, which will have resolution 82 DPI and will fill the rectangle with size 113x100 mm. But I thought that you have picture 70x70 pixels and you want to scale it. You have two possibilities if you want to have bigger picture:

    1) change DPI on the picture (it means change the scale used to show the picture, no change of details or data in the picture, each pixel will be bigger or smaller...) - can be done through my example
    2) change pixel size of the picture (it means change size of the BMP, using same scale for displaying, size of pixel will be same, more pixels will be used to display the image...) - you need to create new image from the source...

    I do not know, if I understand what you want to do. But the calculation is correct...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • jksjks Member Posts: 277
    Thanks kine.
    Actually 70x70 is not the size of the image which I want to scale. But the scaled image. ( Actually currently I scale it to this fixed value of 70x70).

    Kine, can you please tell me how you have calculated DPI of 82. I got somewhat confused.

    Please help.
  • kinekine Member Posts: 12,562
    PixelsX = 1024 = Width in pixel of the device
    PixelsY = 768 = Height in pixel of the device
    MMX = 320 = Width in mm of the device
    MMY = 240 = Height in mm of the device

    It means for me that 1024 pixels have 320 mm on the device...

    Google Calc: 320 millimeters = 12.5984252 in

    => 1024 pixels = 12.5984 inch
    DPI = pixel/inch = 1024/12.5984 = 81.28 = 82 dots per inch (Rounded up)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • kinekine Member Posts: 12,562
    82 DPI => 17'' screen with resolution 1024 x 768 see table on http://www.scantips.com/basics1a.html 8) 8) 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • PhennoPhenno Member Posts: 630
    Just a little addon.

    I had to find a size (W/H) of a BMP on file sistem...

    with this little code (and with help of this thread) I was able to read it through file:
        F.TEXTMODE(FALSE);
        F.OPEN(FName);
        F.SEEK(18); 
        F.READ(FWidth);
    
        F.SEEK(22);
        F.READ(FHeight);
        F.CLOSE;
    

    Where FWidth and FHeight are integers.
Sign In or Register to comment.