Image processing library

TWELVE

Active Member
Licensed User
Hi Andrew,

can you explain the release method more in detail for me..?

I searched the whole thread of the ImageLibEx, but you only mentioned that you added this to the lib, not how to use.I read the help, i understand, that i need to assign a new bitmap to the BitmapEx before i can release it, but i don't know how.

This is was my code basically does, a simple resize:

B4X:
Image1.LoadPicture(MyImage) 
Image1.Visible= True
BitmapEx.New3(Image1.image)
BitmapEx.Zoom(25)
BitmapEx.Release
BitmapEx.SaveImage(MyImage,"J")

This is giving me an error message, obviously because i missed something...

Edit:


I found - by accident - , that this piece of code is working without giving an error message:

B4X:
BitmapEx.New1(MyImage)
BitmapEx.Zoom(25)
BitmapEx.SaveImage(MyImage,"J")

I assume that it's working because it uses a BitmapEx bitmap that does not lock the file as the .net bitmap does.This is handy for me because i do not need the image object in that particular case, but i'm still interested in how the release method works.


regards,

TWELVE
 
Last edited:

agraham

Expert
Licensed User
Longtime User
B4X:
BitmapEx.Release [COLOR="Red"]' Doom![/COLOR]
BitmapEx.SaveImage(MyImage,"J")
That errors because Release disposes the bitmap so there is nothing to save.

B4X:
BitmapEx.Zoom(25)
BitmapEx.SaveImage(MyImage,"J")
That works because, from the help for Zoom "This method disposes the existing internal bitmap and creates a new one." so the existing bitmap is disposed releasing the lock on the file letting you save back to it. Note that the help entries for the BitmapEx methods document what happens to the internal bitmap letting you manage the bitmaps appropriately.
 

TWELVE

Active Member
Licensed User
Hi Andrew,

first of all - thanks for that library.It's working fine on the desktop, but when i tested on my device ( old-fashioned PPC2003SE iPaq Device ;-) ), i get an out of memory exception during resize ( zoom) operation.My device is not that good equiped with RAM, but there are still around 20 mbytes for programs and data each available.

The exception lets assume that there's not enough memory, but how much does it need for an image of lets say 3MPixels ? How can i know if the size of memory is an issue for a particular image without throwing a .NET exception to the user..?

In my opinion the memory should be sufficient for that kind of images...are there possibly other issues i should aware of..?

If ram mem is the issue, does the PPC/WM support some kind of virtual memory / paging as used on windows PCs..?

Is something like memory allocation needed for the BitmapEx ( ...if a certain is size is exceeded..? ).

I hope you got some answers / solutions for me since i really need that size down feature to reduce the network traffic.

I use the simple code i posted in the examples above...


regards,

TWELVE
 

agraham

Expert
Licensed User
Longtime User
In an ImageEdit object a 3Mpixel bitmap will occupy approximately 9MB of memory as a standard 8 bit RGB bitmap and an additional 18MB as the linearised 16bit RGB bitmap values that are actually being manipulated so it is no wonder that you are running out of memory. Those images are just too large for ImageEdit on a device and there is nothing you can do about it.

What are you trying to do with ImageEdit on the device that you need to manipulate such large bitmaps?
 

TWELVE

Active Member
Licensed User
What are you trying to do with ImageEdit on the device that you need to manipulate such large bitmaps?

My App can transfer user images into a blog, taken from a digicam whatever...because my App is mostly used in foreign countries using GPRS or UMTS data connection, the amount of data being transfered is an very important factor - 1 Euro per 100Kbytes is a usual fee.So i give the user the opportunity to reduce the transfer volume by scaling down the image to a couple of predefined image sizes.

I could accept the fact, that a certain amount of RAM is needed for that, which is not available on older devices - apparently.But i would like to catch that ugly exception and inform the user "hey your device is not suitable for this" before that exception ever occured.

So can i calculate what amount of ram would be needed..?

regards,

TWELVE
 

agraham

Expert
Licensed User
Longtime User
ImageEdit is not the correct library for this. You should use either BitmapEx.Zoom from ImageLibEx to resize and save the images or my http://www.b4x.com/forum/additional...ry-display-large-images-device.html#post30129. However if you are distributing your app to other users there is a licensing condition that you or they pay for a license to use the Jpeg library as the license I negotiated for Basic4ppc users covers you for your own use only.
 

TWELVE

Active Member
Licensed User
ImageEdit is not the correct library for this. You should use either BitmapEx.Zoom from ImageLibEx to resize and save the images or my http://www.b4x.com/forum/addit...html#post30129.

I forgot to mention that i already use the ImageLibEx for the scaling..i changed to it because of the GDI+ error i received with the ImageEdit due to the issue with the save to the original image file - and as i found later - because ImageLibEx is handling the acpect ratio by itself.


However if you are distributing your app to other users there is a licensing condition that you or they pay for a license to use the Jpeg library as the license I negotiated for Basic4ppc users covers you for your own use only.

I had a look into that piece, but could not find any resizing functionality....did i overlook something..?


regards,

TWELVE
 

agraham

Expert
Licensed User
Longtime User
- and as i found later - because ImageLibEx is handling the acpect ratio by itself.
I don't understand the aspect ratio comment but ImageLibEx will do what you want if you manage the bitmaps correctly. DrawerEx.DrawImage will let you crop or copy parts of images and even zoom them. BitmapEx.Zoom is in fact a convenience function that does the same as DrawerEx,DrawImage but handles the bitmap management for you.
I ... could not find any resizing functionality....did i overlook something..?
Yes. The whole purpose of that library is to resize and display or save large images that otherwise could not be handled by a device and would give out of memory problems. Look at the help and demo. Note that the license, as noted in the help, requires that you, or the recipient pay a fee when you pass an application using the library to another person regardless of whether you sell it or give it away it for free.
 

TWELVE

Active Member
Licensed User
I don't understand the aspect ratio comment but ImageLibEx will do what you want if you manage the bitmaps correctly.

I mentioned that because the ImageLib need extra aspect ratio calculations while ImageLibEx does not.But this part is not important.

Yes. The whole purpose of that library is to resize and display or save large images that otherwise could not be handled by a device and would give out of memory problems. Look at the help and demo.

I have had...i wouldn't have asked if the help would be mentioning any resize functionality.I will check again...

Meanwhile i tested a bit with different images, none worked on the device.Images that are too large gives an ooM excpetion, smaller images gives an "NotSupportedException".So what's this..???

I'm still talking of ImageLibEx lib and the errors only occur on the device.

Edit:

These are the methods of the jpeg lib...no zooming / scaling at all:

GetSize(filename As String)

Load(filename As String)

LoadArea(filename As String, x As Int32, y As Int32, width As Int32, height As Int32, highquality As Boolean )

LoadThumbnail(filename As String, destwidth As Int32, destheight As Int32, highquality As Boolean )

New1 : Creates a new Jpeg object.

Save(bitmap As Bitmap, filename As String, quality As Int32)

I found this one interesting:

Load(filename As String) : On the device the Bitmap is created line by line avoiding reading the entire file into memory before decoding it so saving some memory use but as the entire bitmap is created at full size using it for large images will cause memory problems. This method sets the Height and Width properties.

But i could imagine that LoadThumbnail() could do the job...



regards,

TWELVE
 
Last edited:

agraham

Expert
Licensed User
Longtime User
if the help would be mentioning any resize functionality
LoadThumbnail and LoadAreaThumbnail. The demo actually shows both a fullsize and an area crop resize save taking place.
"NotSupportedException".So what's this..???
I've no idea as you don't state the function that is in error but maybe you are trying to save in a format that the device doesn't support. Many devices only support jpg.
 

TWELVE

Active Member
Licensed User
I've no idea as you don't state the function that is in error but maybe you are trying to save in a format that the device doesn't support. Many devices only support jpg.

It happens at the same stage where the ooM occurs.Somewhere around here:

B4X:
BitmapEx.New1(MyImage)
BitmapEx.Zoom(25)
BitmapEx.SaveImage(MyImage,"J")

I save in jpg format.

regards,

TWELVE
 

TWELVE

Active Member
Licensed User
They do rescale!

I know meanwhile and you also confirmed it with your last post:

But i could imagine that LoadThumbnail() could do the job...

Quote:
Originally Posted by TWELVE
if the help would be mentioning any resize functionality

LoadThumbnail and LoadAreaThumbnail. The demo actually shows both a fullsize and an area crop resize save taking place.

That lib is really appropriate for my usage, the only drawback is the license thing.Which doesn't matter currently for my own use...

I would be still interested into a solution for the "NotSupportedException" thingy.It happens exactly here:

BitmapEx.SaveImage(MyImage,"J")

regards,

TWELVE
 

TWELVE

Active Member
Licensed User
I would be still interested into a solution for the "NotSupportedException" thingy

I found it based on your comment, but i'm a bit curious about it: Only if i save the image as .bmp, it works without throwing that exception.Does this mean, i cannot save JPGs on my device..? I use old fashioned PPC2003 device with CF 3.5.

regards,

TWELVE
 

agraham

Expert
Licensed User
Longtime User
II would be still interested into a solution for the "NotSupportedException" thingy.
That normally would mean that the device does't support saving the bitmap in the requested format. However a format parameter of "J" looks fine so I'm sorry but I don't understand what the problem might be.
 

agraham

Expert
Licensed User
Longtime User
the only drawback is the license thing.
To clarify the license. You only need to buy a single license to be classed as a developer. It's not very expensive at about 30 Euros and you can then distribute as many copies of any applications using it as you want. See About - JPEGator - dzenisiuk.info

About saving jpgs. I'm a bit rusty on ImageLibEx but the comment in the ImageLibEx help that devices can normally only save jpgs may be wrong, it might be only bmps which is probably why I put a Save method in the Jpeg object that can save jpgs on the device from any image or bitmap as the demo shows.
 

TWELVE

Active Member
Licensed User
Let's say, i would limit that particular feature to WM5 > Users without locking out PPC2003 Users entirely, how can i test for the OS before calling that function without risking expections...?

Any other suggestions on how 2003 can deal with jpg files...?

regards,

TWELVE
 
Top