none
Images already scaled when imported? RRS feed

  • Question

  • I have created a graphic that is 36x64 pixels.  When I import the image, ImageList.GetHieghtOfImage() returns the correct value.  However if I draw a box around the image with the height and width set from the computer values, the box is much bigger than the image.  The same thing happens if I don't use the computed values but use the known sizes.  It looks to be around the ratio of 72/120.  So I assume it is some resolution issue. As you can see in the picture the castle icon is not the size it is supposed to be.  The only code that I have used is below.  Is this a bug or is this intentional?  Why would images get scaled.  If it is a dpi problem, why does the program care about dpi?  Images are pixels, pixels should not change unless the programmer changes them.


    wrongSize
    castle1 = ImageList.LoadImage(Program.Directory + "\castle1.png")
    castle[1] = Shapes.AddImage(castle1)
    Shapes.ShowShape(castle[1])
    Shapes.Move(castle[1], 0, 0)
    GraphicsWindow.DrawRectangle(0,0,ImageList.GetWidthOfImage(castle1),ImageList.GetHeightOfImage(castle1))
    

    Friday, February 19, 2010 8:06 PM

Answers

  • John,

    Thanks for the effort creating and uploading the files - this issue is reproduced - we now have a clear test case.

    With GIMP you can get round it by unchecking the 'Save resolution' when saving as a png and this works (gets the right size and preserves all the transparency) - I guess this information is probably being used by SmallBasic to internally convert the png to somethig else in the .Net framework.  If the image is created with some other application that includes this resolution data it may be hard to remove without something like GIMP that has plenty of options.

    Hopefully Vijaye will look into this further at some point.



    EDIT

    The same effect can be achieved for example with Paint.NET by setting the resolution (canvas size) to 96 ppi (pixels per inch).
    Friday, February 26, 2010 7:27 PM
    Moderator

All replies

  • Hi Willy,

    SmallBasic is very touchy with it's image loading, as I asked almost the same question a couple of months back in v0.7 of SB.

    You can see Serdan's reply to my question and a workaround to the problem in this thread here - which suggests using a different application to save the image to disk.  

    I believe it's a bug in SB because all the images I used were saved with the same software, but some of them were scaled down (as you have experienced) and some appeared at the proper size.

    Either scales the images in SmallBasic (which I did as I couldn't be bothered to process them through another image app) or do as the thread suggests.

    Hope that helps.
    Friday, February 19, 2010 9:12 PM
  • The problem with scaling is you lose the upper left corner as the reference point.  I havn't tried rotating the scaled image but it may also rotate from some other point.  I guess I will try and find a program the can convert pngs to the right resolution.

    Thanks!
    Saturday, February 20, 2010 4:11 AM
  • willy134,

    As you suggested, perhaps you can apply scaling to the image if you cannot get the correct imported scaling.

    With regard to the scaling and rotation in SmallBasic, the key is to store the current scaling and rotation in variables.  Also, the rotation is with respect to the image centre, and the coordinates are relative to the upper left corner.

    With this it is possible to scale, rotate and move an image and know where everything is so that a shape bounding the image can be drawn.

    All the information should be available, but it will depend on your program how you choose to use it and for what purpose.  It is possible to calculate the coordinates of the bounding box too.

    Import XDW587-0 as an example doing all this (use the arrow keys to rotate and scale the image)

    Good luck
    Saturday, February 20, 2010 10:43 AM
    Moderator
  • I had the same problem before after editing a png with adobe photoshop, I unfortunately gave up trying to get it to scale right.  I wasn't sure if it was adobe or smallbasic. 
    Sunday, February 21, 2010 5:34 AM
  • I haven't actually had this issue, can anyone upload somewhere any images that have the problem.
    Thursday, February 25, 2010 7:26 PM
    Moderator
  • Took me 3 minutes to create the png file as I have had the same problems,
    it has happened on every png file I have created using GIMP (30+) I then took
     4 hours to create a Skydrive and upload!!

    I tried uploading the file to skydrive but it converted them all into
    gif files. There is probably some option I am missing so I created
    a zip file with everything in it.



    the  files can be downloaded from a zip file at


    http://cid-3a757d41e536b3e5.skydrive.live.com/browse.aspx/.Public


    Note a png file created from MSpaint works correctly but I could not
    find out how to make transparency using paint. These png files
    were created using GIMP. If you open the orange and blue png files
    in MSpaint then resave them they become the correct size, except
    the blue file looses its transparency. (Magenta does not show through
    in the center.)

    All files are 64x64 pixels.

    64x64bmp.bmp - bmp from MSpaint red square
    64x64jpg.jpg  - jpg from MSpaint green square
    noalpha64x64png.png - png no alpha channel(ie no transparency) from GIMP orange square
    64x64png.png - png file from GIMP with transparency blue square

    I have tested the download on my computer but if you have problems let me know.
    Friday, February 26, 2010 3:26 PM
  • John,

    Thanks for the effort creating and uploading the files - this issue is reproduced - we now have a clear test case.

    With GIMP you can get round it by unchecking the 'Save resolution' when saving as a png and this works (gets the right size and preserves all the transparency) - I guess this information is probably being used by SmallBasic to internally convert the png to somethig else in the .Net framework.  If the image is created with some other application that includes this resolution data it may be hard to remove without something like GIMP that has plenty of options.

    Hopefully Vijaye will look into this further at some point.



    EDIT

    The same effect can be achieved for example with Paint.NET by setting the resolution (canvas size) to 96 ppi (pixels per inch).
    Friday, February 26, 2010 7:27 PM
    Moderator