ImageLibEx library

agraham

Expert
Licensed User
Longtime User
I assume that mapslist is a Basic4ppc ImageList. It looks to me like a problem with that. I've not looked at ImageList before and assumed it stored bitmap references. In fact it appears that it can store bitmaps as both string filenames and as bitmap references. As ImageList is not as separate control but is implemented by inline code in both the IDE and optimising compiler I can't be sure but it looks as though normally the IDE/compiler compensates for this but in your instance it may not be and is passing an image filename as a string to DrawImage - hence the complaint.

The above is my best guess unless you can post some code that displays this behaviour.
 

derez

Expert
Licensed User
Longtime User
Andrew
I feel that you are right, I am going to check it - by assigning the imagelist item to a bitmap, and from there to the drawer.

Thanks

Edit: Yes, that solved the problem.
Thanks again !
 
Last edited:

agraham

Expert
Licensed User
Longtime User
I'm having a bad few days suffering from a bad winter cold and I suspect my glib reasoning above is not the reason for the problem as I am now doubting my observation about both string names and references being stored in an ImageList. However it does seem that ImageLists, or at least, what is returned from the ImageList.Item(x) method, are treated differently in the IDE and when optimised compiled so I don't really understand what is going on here.

It seems when optimised compiled an ImageList should only contain references, as I previously assumed, so I have no idea why it was trying to pass a string to DrawImage. Perhaps Erel might shed some light on this as it looks like it might be a bug.

You didn't confirm that mapslist was a Basic4ppc ImageList but it seems so.

Was the offending image assigned to the ImageList at design or runtime?

Did this happen with more than one image?

Were there a misture of images in the ImageList assigned at design and runtime?

Is "compilation to desktop " optimised compiled?

You don't have some example code that produces the problem you could post do you?
 
Last edited:

derez

Expert
Licensed User
Longtime User
Andrew

You didn't confirm that mapslist was a Basic4ppc ImageList but it seems so.
Sorry for omitting what was clear for me, yes it is.

Was the offending image assigned to the ImageList at design or runtime?
At runtime, the list contains 10 maps of 1000*1000, they are assigned by: mapslist.item(i) = [filename]

Did this happen with more than one image?
- yes.

Were there a misture of images in the ImageList assigned at design and runtime?
No, all 10 are assigned at runtime.

Is "compilation to desktop " optimised compiled?
Yes.

You don't have some example code that produces the problem you could post do you?
No, I have a small test program in which the problem does not appear and I attach it without the map (which is 467 KB).

In the meantime - my nav prog is running with the intermediate image but it slows the process meaningfully, so enabling the use of imagelist item in the darwimage will be great advantage for me.

Thank you.
 

agraham

Expert
Licensed User
Longtime User
No, I have a small test program in which the problem does not appear and I attach it without the map (which is 467 KB).
I am afraid that is not much help. I, or Erel, need to see the problem. I suspect something in the code of the failing application may be confusing the optimised compiler.

To look further we would need either some failing source code or a zip of the Class1.cs file produced after compiling the failing application which is in YourUserName\AppData\Roaming\Anywhere Software\Tzor in Vista or Documents and Settings\YourUserName\Application Data\Anywhere Software\Basic4ppc\Tzor in XP and indicate the name of the Sub where the bitmaps are assigned to the ImageList and also the Sub name where the DrawImage fails.
 

derez

Expert
Licensed User
Longtime User
Sorry, that code is not for publishing.
I'll try to create the error in a demo program.
 

derez

Expert
Licensed User
Longtime User
The relevant subs:
Initializing the mapslist content:
B4X:
...
For i = 1 To 10
  mapslist.Add(AppPath & "\maps\blank.jpg")
Next
...

then the runtime assignment of maps:
B4X:
Sub replace_all_maps(a,b)
temp = map_header
ind = 0
For i = a-1 To a+1
  For j = b+1 To b-1 Step - 1
    ind = ind + 1
    FN = temp & Format(i,"D2") & Format(j,"D2") & ".jpg"
   If FileExist(FN) Then  mapslist.Item(ind) = FN    Else mapslist.Item(ind) = mapslist.Item(0)

  Next
Next
End Sub

The relevant part of sub Israel_map_move:

B4X:
...
mapdst.New1(0,0,IW,IH)
mapsrc.New1(left,top,IWZ,IHZ)
'image1.Image = mapslist.item(5)
drx.DrawImage(mapslist.item(5),mapsrc.Value,mapdst.Value,False)
...

If I replace the "mapslist.item(5)" by the image1.image after assigning it the item - it works.

The error appears only in runtime, not while compiling. It was optimized compiled for desktop.

I attach the class1.cs file.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
It's a bug in your code I'm afraid ( EDIT - no it's not ). I've rearranged the IF statement as I don't like single line IFs.

B4X:
If FileExist(FN) Then
    mapslist.Item(ind) = FN [COLOR="Red"]' Error! assigning a string not an image[/COLOR]
Else
    mapslist.Item(ind) = mapslist.Item(0) [COLOR="SeaGreen"]' OK, this is an image assignment[/COLOR]
End If
This works in the IDE because the assignment checks if a string is being assigned and reads the bitmap from the file if it is a string. The optimising compiler just does the assignment without checking.

EDIT:- :sign0013: I've just looked at the help for ImageList.Item and it states that what you are doing should work so it looks like a compiler bug.
 
Last edited:

derez

Expert
Licensed User
Longtime User
Andrew

You say it is a compiler bug. Is it even so that the error appears in runtime, not while compiling ?
 

agraham

Expert
Licensed User
Longtime User
Yes. In order to do what the help says is permissible, and works in the IDE, the compiler should be compiling a call to a function called GetBitmapFromString which checks at runtime whether the assignment is a string and if so reads a bitmap from the filename specified by the string. The compiler does this for the parameter to ImageList.Add(something) producing
ImageList.Add(GetBitmapFromString(something))
but not for an assignment to ImageList1.Item(somewhere) where it produces
ImageList1.Item(somewhere) = something
instead of
ImageList1.Item(somewhere) = GetBitmapFromString(something)
 

derez

Expert
Licensed User
Longtime User
Thanks for the explanation.
In short - Somewhere something goes wrong...
 

derez

Expert
Licensed User
Longtime User
I suspect that this is not the case.

The saga started when I decided to draw the maps on an image, instead of on the form, so that when rotated it will not have blank areas (by using an image larger then the form.

I was using previously this line:
B4X:
form7.DrawImage(maps.Item(5),left,top, lmore ,tmore)

and never had such error.

The difference is using imagelibEX function, so the problem is not in the compiler only. If the compiler adds GetBitmapFromString(something) then it should be added in imagelibEx internal code.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
so the problem is not in the compiler only.
I've had a look at a lot of generated ImageList code over the the last 24 hours and I'm afraid it is unless Erel intended ImageList to only work properly with Form.DrawImage, or the intrinsic Image control, which I doubt.

Form.DrawImage is specified to take either a filename or a bitmap as a source image and the compiler ensures this by compiling in GetBitmapFromString for the source bitmap parameter. This is a special case, which is undesirable but I suspect is supported for backwards compatibility from before ImageLib.Bitmap was available.

Both ImageLib.Drawer.DrawImage1 and ImageLibEx.DrawerEx.DrawImage are specified to only accept a bitmap as a source image. For neither of these does the compiler include GetBitmapFromString which is understandable as they would be special cases and the compiler shouldn't make assumptions about external libraries. Instead the compiler sensibly tries to ensure that ImageList only holds bitmap references by compiling in GetBitmapFromString for ImageList.Add and ImageList.Insert. It also compiles in a similar GetBitmapFromResource function when adding the bitmaps specified at design time. To ensure the only references are held it should also do that for a direct assignment to ImageList.Item(x) which it doesn't do. I regard that as a compiler bug.
 

derez

Expert
Licensed User
Longtime User
OK. Why there is no compiler problem in the test program I attached before (extest) ?
It is using the same code:
B4X:
drawer.DrawImage(maps.Item(5),mapsrc.Value,mapdst.Value,False)
 

agraham

Expert
Licensed User
Longtime User
Version 2.0 posted with an Icon object that can retrieve the default icon from an exe or dll and transform it into a bitmap if required. There is not much else it can do as the .NET Icon class has restricted functionality in the Compact Framework - and not much more on the desktop!
 

derez

Expert
Licensed User
Longtime User
Andrew
I am glad for this improvement but cant get it to work, please tell me what i'm doing wrong, trying all possible combinations with the code below:
B4X:
Sub App_Start
   Form1.Show
   img.New4
'   image1.Image = AppPath & "\startup.ico"
   icn.New1( AppPath & "\startup.ico")
   icn.Value = icn.GetIcon0(AppPath & "\startup2.exe",True)
   img.Value = icn.ToBitmap(icn.Value)
   form1.Text = icn.ValueIsNull
   image1.Image = icn.Value
End Sub

img is bitmapEX object, icn is icon object, image1 is an image control.
From the marked line alone I get the icon on the image. the form text is false as required but the image is null...
 
Last edited:

derez

Expert
Licensed User
Longtime User
CoreDll ?

Hi Agraham,

I am studying the gradient fill issue, starting from this library.
I tried to compile the exact file using sharpdevelop 2 and succeeded only with the desktop version.
With the Device, it finishes the compilation but when I run the application that use the library it creates the attached error.
I downloaded this coredll.dll and put it everywhere but nothing helps.

In the source it has this line:
[DllImport("coredll.dll", SetLastError = true, EntryPoint = "GradientFill")]

What should I do ?

Edit: Foolish me, it doesn't run on the Desktop but it runs on the device !

Thanks
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…