none
Trouble with DrawImage RRS feed

  • Question

  • I cannot get the DrawImage command to work in smallbasic. I imagine the simplest way would be to load the image from a file:

    image1 = ImageList.LoadImage("C:\pic2.jpg")
    GraphicsWindow.DrawImage(image1,0,0)

    However nothing appears. The path is correct, the file exists etc but there's no joy on seeing in the GraphicsWindow frame.

    I have seen other threads that include a variable or number in the LoadImage command (e.g. ImageList.LoadImage(1, "C:\img1.jpg")) - but this gives me an error as LoadImage only takes 1 arguement.

    I must be missing something obvious here.

    Monday, June 13, 2011 4:44 AM

Answers

  • GRM701,

    It should (and does for me) work using ImageList with DrawImage.  A couple of things to try:

    1] Put your jpg in a directory that you normally have access (often C: can behave differently) such as your Documents folder.

    2] Try putting a Program.Delay(1000) between the ImageList and DrawImage commands, just in case there is some part of the ImageList process that isn't fully completed before the DrawImage - this has been seen before with slow to download images - not probably the issue here, but worth a try.

    3] Try some of the suggestions here (especially the last that copies a jpg from the net and loads the locally stored image), a similar problem

    Monday, June 13, 2011 6:21 PM
    Moderator
  • Try doing it without imagelist. Use this:

    GraphicsWindow.DrawImage("http://www.myanmars.net/myanmar-history/albert-einstein.jpg", 0, 0)

     

    It may take a bit to load the file, but it should work. But I suggest you use the Shape class, so you can move the image around, and remove it when you want without having to clear the GraphicsWindow each time.


    ~~AirWaves!!~~
    • Proposed as answer by Kirkkaf Wednesday, June 15, 2011 8:06 AM
    • Marked as answer by litdevModerator Tuesday, June 21, 2011 8:34 PM
    Monday, June 13, 2011 5:26 AM
  • Hi Litdev,

    Thanks for the information - all helpful.

    I've finally figured out what's been the problem - I think! Your first point gave me the clue and as it turns out my directory set up has an interesting foible of having a 'C:\....My Documents\My Documents\...', so that solved one problem. The other one was the misinterpretation of the Windows extension protocol - Windows Explorer (I'm still using XP) shows the file name without the extension and I assume automatically assigns one depending on the file type, whereas I had renamed a picture 'pic1.jpg', hence Windows assumed it was actually called 'pic1.jpg.jpg'. So there's a trap for young players to be aware of.

    As is often the case it seems to be a 'can't-see-the-wood-for-the-trees' type issue.

    Your last reference was also handy to have - cheers

     

    Tuesday, June 14, 2011 1:23 PM

All replies

  • Try doing it without imagelist. Use this:

    GraphicsWindow.DrawImage("http://www.myanmars.net/myanmar-history/albert-einstein.jpg", 0, 0)

     

    It may take a bit to load the file, but it should work. But I suggest you use the Shape class, so you can move the image around, and remove it when you want without having to clear the GraphicsWindow each time.


    ~~AirWaves!!~~
    • Proposed as answer by Kirkkaf Wednesday, June 15, 2011 8:06 AM
    • Marked as answer by litdevModerator Tuesday, June 21, 2011 8:34 PM
    Monday, June 13, 2011 5:26 AM
  • Thanks for that Airwaves. It does work and I've tried other web based images successfully.

    However, is it then true that only images from web pages can be used in DrawImage?

    No matter what I try I can't seem to get a jpeg file to be read from a file.

     

    cheers

     

    p.s. thanks for the tip about the Shape class - good idea.

    Monday, June 13, 2011 7:23 AM
  • GRM701,

    It should (and does for me) work using ImageList with DrawImage.  A couple of things to try:

    1] Put your jpg in a directory that you normally have access (often C: can behave differently) such as your Documents folder.

    2] Try putting a Program.Delay(1000) between the ImageList and DrawImage commands, just in case there is some part of the ImageList process that isn't fully completed before the DrawImage - this has been seen before with slow to download images - not probably the issue here, but worth a try.

    3] Try some of the suggestions here (especially the last that copies a jpg from the net and loads the locally stored image), a similar problem

    Monday, June 13, 2011 6:21 PM
    Moderator
  • Hi Litdev,

    Thanks for the information - all helpful.

    I've finally figured out what's been the problem - I think! Your first point gave me the clue and as it turns out my directory set up has an interesting foible of having a 'C:\....My Documents\My Documents\...', so that solved one problem. The other one was the misinterpretation of the Windows extension protocol - Windows Explorer (I'm still using XP) shows the file name without the extension and I assume automatically assigns one depending on the file type, whereas I had renamed a picture 'pic1.jpg', hence Windows assumed it was actually called 'pic1.jpg.jpg'. So there's a trap for young players to be aware of.

    As is often the case it seems to be a 'can't-see-the-wood-for-the-trees' type issue.

    Your last reference was also handy to have - cheers

     

    Tuesday, June 14, 2011 1:23 PM