Alpha Image Device

eww245

Member
Licensed User
Here is a library that I created a few months ago for loading Alpha transparent Images on the PPC.
It utilizes a Com component called IImagingfactory that was implemented in Windows Mobile 5.
So this will only work with WM5 or higher with .NET Compact Framework 2.0 or higher.

The methods of interest are DrawImage and ImageOnSection.
Images can be loaded from file, byte[] array, or an embedded resource.

GetImageSection will get a section of the back image that can be used with any control supporting images.
ImageSection is a reference to that image.

Images can be drawn in the foreground, allowing for dynamic replacement.
Background images should be loaded before any foreground otherwise some images will be lost.
An embedded image in a seperate Dll can be loaded with GetImageResource , for those that are able to do so.

DrawString is included which is able to draw text centered on the form, AlphaBlend is also included.

This is a a fully functional beta release that will likely change in the future.
Have Fun :), and please post any Questions Comments or Requests.
 

Attachments

  • Alpha6.zip
    127.6 KB · Views: 92
Last edited:

agraham

Expert
Licensed User
Longtime User
Have you got a demo app you could post? Also a compatible desktop library for development would be useful. The present library needs to be added to the desktop for optimised compiling to work but the desktop crashes if you try to run it.

It looks like at the moment it only works for Form images. It would be nice if there was an AlphaBitmap class that drew on an internal bitmap and could open and blend images with alpha values. If it returned that internal image as a Value property it could then be used in conjunction with ImageLib and ImageLibEx bitmaps. I don't know if a bitmap format conversion would be needed or not - I'm not so hot on graphics stuff.

I suspect, but haven't tried, that it will need some modification to work when AutoScale compiled. http://www.b4x.com/forum/beta-versions/4207-autoscale-compilation-mode-external-libraries.html
 

eww245

Member
Licensed User
Have you got a demo app you could post? Also a compatible desktop library for development would be useful. The present library needs to be added to the desktop for optimised compiling to work but the desktop crashes if you try to run it.

It looks like at the moment it only works for Form images. It would be nice if there was an AlphaBitmap class that drew on an internal bitmap and could open and blend images with alpha values. If it returned that internal image as a Value property it could then be used in conjunction with ImageLib and ImageLibEx bitmaps. I don't know if a bitmap format conversion would be needed or not - I'm not so hot on graphics stuff.

I suspect, but haven't tried, that it will need some modification to work when AutoScale compiled. http://www.b4x.com/forum/beta-versions/4207-autoscale-compilation-mode-external-libraries.html

ImageSection would be that value, but it is not settable.

What I'll do is add another method that can draw a Bitmap on it and also make the property settable.

I'm quite spoiled by the device IDE, it's where I develop everything and only use the desktop for compiling and it doesn't crash.
The cPPc property didn't work for me before, I'll just have to figure it out.

As of now I don't think I'll be able to make a Desktop version, other than a dummy.

Right now I'm adding some new features so I'll get a demo ready when it's done.
 

agraham

Expert
Licensed User
Longtime User
As of now I don't think I'll be able to make a Desktop version, other than a dummy.
Why not? It would be a shame if you didn't and you seem more than competent enough! I would have thought it would be easier on the desktop as the GDI+ stuff is exposed in .NET, so you don't need COM, and AlphaBlend is in gdi32.dll.
 

eww245

Member
Licensed User
Why not? It would be a shame if you didn't and you seem more than competent enough! I would have thought it would be easier on the desktop as the GDI+ stuff is exposed in .NET, so you don't need COM, and AlphaBlend is in gdi32.dll.

Ok, I'll check it out.
 

Byak@

Active Member
Licensed User
Good work ,eww245! I'm hope you don't throw it!
Without sample i can't understand...this lib can load Alpha Transparented images from png\ico and draw it (now on form)?
 

eww245

Member
Licensed User
Good work ,eww245! I'm hope you don't throw it!
Without sample i can't understand...this lib can load Alpha Transparented images from png\ico and draw it (now on form)?

Yes it can draw png's with an alpha channel. No it does not load ico's, but I'll look in to it.

For now I'm not going into too much detail here but I have added a bunch.

There are three classes Alpha AlphaImage ImageList
I took agrahams suggestion and added the seperate class for a non form image.
ImageList was added for regular Bitmaps because Basic4ppc ImageList only keeps a reference to an image, not making a copy.

AlphaImage has AdjustBrightness, AdjustContrast, AdjustGamma, Rotate and Flip along with the same methods as Alpha.
These are part of the IBitmapImage object that I've finally been able to understand.
Anyone's guess is as good as mine for the value ranges, except for Flip, it is bool and bool.

I removed drawing in the foreground, Form.DrawImage acts as a foreground so it's not needed.
Also a memory leak, I believe, is solved, at least for most methods.

The first post has been updated with these changes and a demo, Door and BinaryFile are needed.
BinaryFile is a complement to this as the embedded images can be loaded into a byte[] array.
Door isn't needed but a few methods helped with the demo.

I'm still finding something new with this often so this could eventually be quite a large library.
 

Byak@

Active Member
Licensed User
oo,It is a really good work!many thanks!
maybe you create a dummy(or not) lib for PC?some of my projects work on Desctop and on device.
 

eww245

Member
Licensed User
oo,It is a really good work!many thanks!
maybe you create a dummy(or not) lib for PC?some of my projects work on Desctop and on device.

Yes, I have started working on a Desktop version, but having trouble with the AlphaBlend API.
No errors it just won't work.
Transparency obviously isn't a problem on the Desktop.

I'm trying to figure out an equivalent for Flip Brightness Gamma and Contrast.
For the device it now will only make these changes to the transparent image, not effecting the backimage.

I'll update it here as soon as I resolve some of these issues.


There is the ability to install, uninstall, Encoders and Codecs.
I'm guessing creating custom versions.
And a huge list of ImageTags that can be set or retrieved.
Although this is probably more difficult I'm willing to try it if anyone is intrested.

PropertyTag Values
 

Byak@

Active Member
Licensed User
Thanks for answer)You library is a new and big step for b4ppc!now it is a better than lazarus!big thanks!
 

Byak@

Active Member
Licensed User
i'm try to use Alpha.dll with Sprites.dll (i want a AlphaTransparented sprites) but it doesn't work(( maybe i do some wrong?please see my sample!

and when i'm try to compil source with Alpha.dll i have error :(
 

agraham

Expert
Licensed User
Longtime User
The compile error is because the optimising compiler is producing these two declarations.

Alpha.Alpha+ImageList __main_il1 = null;
Alpha.Alpha+AlphaImage __main_ai = null;

The C# compiler is complaining about the "+" in the type name. Replace these with "." and it compiles fine. The reason the compiler is inserting "+" is that ImageList and AlphaImage classes are declared inside the Alpha class. I have never run across this because I don't nest classes. I don't know if this is still valid http://www.b4x.com/forum/questions-help-needed/2663-compiler-error-cs1519.html#post14837 but even if it is I don't really understand why the compiler is complaining as "+" is valid as part of the type name for a nested class :confused: Erel?
 

agraham

Expert
Licensed User
Longtime User
I've been Googling :)
B4X:
class Outer
{
   class Inner
   {
        class FurtherIn
       {
       {
   }
}
Reflection returns "Namespace.Outer+Inner" and "Namespace.Outer+Inner+FurtherIn" as the type names in the fragment above, easily seen in Reflector. The pluses signify nested classes. Reflection also needs the same format to access those classes. I had assumed (silly me!) that a nested class instance declaration would use the same format

Outer+Inner+FurtherIn fred = null;

It doesn't :(, C# requires

Outer.Inner.FurtherIn fred = null;

I have no idea why there is a difference between what the Reflection API uses and what the compiler requires for the same types! Presumably there is or was a reason to be inconsistent but it baffles me :confused:.
 

eww245

Member
Licensed User
i'm try to use Alpha.dll with Sprites.dll (i want a AlphaTransparented sprites) but it doesn't work(( maybe i do some wrong?please see my sample!

and when i'm try to compil source with Alpha.dll i have error :(

I've added the code to your demo needed for the transparent sprites.
The star image was not really in Alpha format, it was AlphaBlended, I've included an edited image

For some reason the explodesprite doesn't show on the collision event.
It happens when using sprite.LoadBitmap, which seems to be the best way to use this library with sprites, if not the only way.
A Bitmap[] array may work but I had trouble getting it to work.

The compile errors shouldn't happen anymore, as agraham explained it was an issue with nested classes. Thanks agraham.

The new version and AlphaDesktop are also included, though there some are dummy methods and AlphaBlend doesn't work yet.
 

eww245

Member
Licensed User
I've added the newest version with AlphaDesktop included.

AdjustBrightness, AdjustContrast, AdjustGamma, Flip, and Rotate now will not effect the backimage.
 

Byak@

Active Member
Licensed User
eww245 big respect and many thanks!
 

Byak@

Active Member
Licensed User
Hello eww24)
i'm play with 'AlphaSprite' sample...in my real app i have gamewindow larger than form. and when i'm try to load all background image to 'alpha' object i have error (i'm think it is becose size of image larger then size of form.yes?).loading only a part of image is not a good idia.
can you help me? maybe you add "GetImageSectio" method to 'AlphaImage' object or it is not real?
 

eww245

Member
Licensed User
Hello eww24)
i'm play with 'AlphaSprite' sample...in my real app i have gamewindow larger than form. and when i'm try to load all background image to 'alpha' object i have error (i'm think it is becose size of image larger then size of form.yes?).loading only a part of image is not a good idia.
can you help me? maybe you add "GetImageSectio" method to 'AlphaImage' object or it is not real?

Yes, the backbuffer is set to the size of the Form.
So an image with a width or height greater than the form won't draw.
I'm trying a few different ways but, as you typed, GetImageSection for AlphaImage probably will be the best.

Also try the below code in a the tick event it should work faster than what I used in your demo.

It is usefull if there is one image per Sprite frame.
I used Rotate as an example because it was the same image.

So where w.png is it can, for example, be a reference to the images in an array then use a.DrawImage instead of Rotate in the For loop.
And what is before the loop wouldn't be needed.

B4X:
  a.GetImageSection (sprite.NextX, sprite.NextY, 24, 24)
  ai.DrawBitmap (a.ImageSection, 0, 0, 24, 24)
  ai.DrawImage (AppPath&"\w.png", 0, 0, 24,24)
        sprite.LoadBitmap(ai.Image, 1, 24, 24, 1)

   gw.Tick

For i = 0 to 7

  a.GetImageSection (sprite.NextX, sprite.NextY, 24, 24)
  ai.DrawBitmap (a.ImageSection, 0, 0, 24, 24)

'  ai.DrawImage (AppPath&"\w.png", 0, 0, 24, 24)

      ai.Rotate(90)
      sprite.LoadBitmap(ai.Image, 1, 24, 24, 1)

    gw.Tick
Next
 
Top