"LoadPicture" Visual Basic replacement 
Author Message
 "LoadPicture" Visual Basic replacement

Hi,

I am working on thumbnail and I have seen that the Visual Basic
function has a vary bad performance to read files in a very short
time, BMP, GIF JPG (JPEG).

I would like to use the Windows API (XP) to manipulate this files.

Does anyone of you can give me any hint on which function I can use to
read and load into the memory or object those files?

Any help is greatly appreciated, thanks in advance, Nick

Home page: http://www.*-*-*.com/



Wed, 09 Feb 2005 23:01:21 GMT  
 "LoadPicture" Visual Basic replacement


Quote:
>Hi,

>I am working on thumbnail and I have seen that the visual basic
>function has a vary bad performance to read files in a very short
>time, BMP, GIF JPG (JPEG).

Which Visual Basic function would that be?

Quote:
>I would like to use the Windows API (XP) to manipulate this files.

>Does anyone of you can give me any hint on which function I can use to
>read and load into the memory or object those files?

The API LoadImage function

--
Richard Mason



Thu, 10 Feb 2005 12:18:52 GMT  
 "LoadPicture" Visual Basic replacement
The function I would replace with a fast one is LoadPicture.

On Sun, 25 Aug 2002 16:18:52 +1200, Richard Mason

Quote:



>>Hi,

>>I am working on thumbnail and I have seen that the visual basic
>>function has a vary bad performance to read files in a very short
>>time, BMP, GIF JPG (JPEG).

>Which Visual Basic function would that be?

>>I would like to use the Windows API (XP) to manipulate this files.

>>Does anyone of you can give me any hint on which function I can use to
>>read and load into the memory or object those files?

>The API LoadImage function

Home page: http://geocities.com/whisky1767


Thu, 10 Feb 2005 14:38:59 GMT  
 "LoadPicture" Visual Basic replacement
LoadImage can manipulate only BMP, right?
I need a more advanced funtion.

Thanks Richard.

On Sun, 25 Aug 2002 16:18:52 +1200, Richard Mason

Quote:



>>Hi,

>>I am working on thumbnail and I have seen that the visual basic
>>function has a vary bad performance to read files in a very short
>>time, BMP, GIF JPG (JPEG).

>Which Visual Basic function would that be?

>>I would like to use the Windows API (XP) to manipulate this files.

>>Does anyone of you can give me any hint on which function I can use to
>>read and load into the memory or object those files?

>The API LoadImage function

Home page: http://geocities.com/whisky1767


Thu, 10 Feb 2005 14:46:24 GMT  
 "LoadPicture" Visual Basic replacement
    Well, the GDI+ API can load all of those formats and more. I never saw
any benchmarking though. You could also try using the OLE IPicture
interface - I believe that is what VB uses...
    In conjunction with GDI+ and an IStream interface, you can read and load
those image files to and from memory. The IPicture interface will also save
to an IStream, but not in the additional formats that GDI+ can. Although,
IPicture can save metafiles and GDI+ v1.0 cannot...

GDI+ VB API Declarations, less one huge enum and ~8 GUID constants, in case
you don't already have them or something better:
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=37541&lngWId=1

    So many nice (and bad) things about GDI+....

Avery


Quote:
> Hi,

> I am working on thumbnail and I have seen that the visual basic
> function has a vary bad performance to read files in a very short
> time, BMP, GIF JPG (JPEG).

> I would like to use the Windows API (XP) to manipulate this files.

> Does anyone of you can give me any hint on which function I can use to
> read and load into the memory or object those files?

> Any help is greatly appreciated, thanks in advance, Nick

> Home page: http://geocities.com/whisky1767



Thu, 10 Feb 2005 16:34:23 GMT  
 "LoadPicture" Visual Basic replacement


Quote:
>LoadImage can manipulate only BMP, right?

Yes, bmp, icon, and cursor.
Presumably you want to load a lot of images and this is taking the time,
rather than processing

Quote:
>I need a more advanced funtion.

GDI+ will handle a number of formats but look through the
dotnet.framework.drawing archive at Google and you'll see that a common
complaint is its speed.

--
Richard Mason



Thu, 10 Feb 2005 20:05:45 GMT  
 "LoadPicture" Visual Basic replacement
    You guys may not believe this, but I just did a quick benchmark of
LoadPicture vs. GDI+ and.... well, here is the benchmarking code:

'----------------------------------------------------------------
Private Sub Benchmark()
   Const LOOPS As Long = 1000
   Const strFile As String = "GrapeBunch.jpg"
   Dim sngVB As Single, sngGDIP As Single
   Dim bitmap As Long, pic As StdPicture
   Dim I As Long

   ' Load via straight VB
   sngVB = Timer
   For I = 0 To LOOPS
      Set pic = LoadPicture(strFile)
      Set pic = Nothing
   Next
   sngVB = Timer - sngVB

   ' Now load via GDI+
   sngGDIP = Timer
   For I = 0 To LOOPS
      Call GdipLoadImageFromFile(StrConv(strFile, vbUnicode), bitmap)
      Call GdipDisposeImage(bitmap)
   Next
   sngGDIP = Timer - sngGDIP

   ' Show the results
   MsgBox "Results:" & vbCrLf & "VB: " & sngVB & vbCrLf & "GDI+: " &
sngGDIP, vbInformation
End Sub
'---------------------------------------------------------------------------
----------------

Guess what the results are? Note that even if I removed Set pic = Nothing,
the VB results were the same.

Here is what I found based on my P3 733 (you may get different numbers
depending on your CPU and video configuration, but with any luck GDI+ should
still be faster):
================================================
JPEG (5% Compression) =  VB: 23 seconds    GDI+: 2 seconds
BMP = VB: 5 seconds       GDI+: 2 seconds
PNG = VB: N/A               GDI+: 3 seconds
GIF (Single frame image) = VB: 30 seconds       GDI+: 2 seconds
TIFF =  VB: N/A     GDI+: 2 seconds
EMF =  VB: 4 seconds    GDI+: 1 second
WMF = VB: 4.29 seconds    GDI+: 4.12 seconds
RLE =  VB: N/A         GDI+: 2 seconds
================================================

NOTE: In the WMF test, VB beat GDI+ once during testing by .12 seconds.
     The image used was the same, and all formats were based off the
original bitmap. Did I somehow cheat VB? I tried to make it as fair as
possible... Heck, GDI+ even had to convert the string to Unicode 1000 times!
Not everything is as slow as everyone claims, granted that some is, but a
few parts are blazing fast...I just wish I knew which were which. Using the
OLE APIs might get VB to load the images a bit faster, but I suspect that it
would not be worth the trouble.

Sidenotes:
    VB beat GDI+ in line drawing (it only got worse when I made GDI+
anti-alias the line, but that is to be expected). I didn't test other
drawing functions but I saw one post that claimed GDI took 20ms and GDI+
took 120ms to paint a 1024x768 image, though I don't think he was using a
Cached Bitmap as those things are pretty fast, so GDI is basically
unbeatable in some areas based on speed right now. See the thread in
microsoft.public.win32.programmer.gdi entitled: "GDI+ and drawing" for more
on that. GDI and GDI+ both have pluses and minus but you shouldn't discount
it from your arsenal unless Win95 or NT3.x or lesser are platform targets.
It is almost a pity that all you hear are horror stories about GDI+ and so
few praising it, though many do both, with emphasis on the horror and
hopefully this post isn't one of them. I suppose in the grand scheme of
things it depends on what you need to get done...

Avery


Quote:


> >LoadImage can manipulate only BMP, right?

> Yes, bmp, icon, and cursor.
> Presumably you want to load a lot of images and this is taking the time,
> rather than processing

> >I need a more advanced funtion.

> GDI+ will handle a number of formats but look through the
> dotnet.framework.drawing archive at Google and you'll see that a common
> complaint is its speed.

> --
> Richard Mason



Fri, 11 Feb 2005 07:40:37 GMT  
 "LoadPicture" Visual Basic replacement
    I knew I had to be cheating VB somehow, and I believe the previous code
was cheating because, whilst it does load the image, I think it just opens
the file for reading (I think GDI+ reads the file on demand, which would
explain why the painting can lag a bit but I am probably wrong), so if you
want to use it somewhere outside GDI+ like GDI, you must create the HBITMAP
and this is the bottleneck. I added GdipCreateHBITMAPfromBitmap and
DeleteObject calls in the GDI+ loop, so here are the hopefully more
realistic results:

================================================
JPEG (5% Compression) =  VB: 18 seconds    GDI+: 16 seconds
BMP = VB: 5 seconds       GDI+: 9 seconds
PNG = VB: N/A               GDI+: 16 seconds
GIF (Single frame image) = VB: 28 seconds       GDI+: 10 seconds
TIFF =  VB: N/A     GDI+: 22 seconds
EMF =  VB: 4 seconds    GDI+: 1 second
WMF = VB: 4.29 seconds    GDI+: 4.12 seconds*
RLE =  VB: N/A         GDI+: 2 seconds
================================================
* I couldn't figure out how to get the handle to the WMF style metafiles, so
I'll have to assume they are fully loaded already. Based on the time
elapsed, it would seem like this would be the case. I think you'd have to
either convert the WMF to a EMF or jump through a few hoops to get the WMF
handle. I think Microsoft is trying to phase them out or maybe I didn't look
hard enough?

Sidenotes:
    I'm somewhat surprised that getting an HBITMAP for a bitmap would take
so much longer in GDI+...hmm, then again LoadImage would probably even beat
VB. GDI+ is much faster at loading GIFs, so I'd think about that if you knew
you were going to load many of those (What is VB doing with those GIFs?!).
The JPEG is basically a tie, with GDI+ only slightly faster, and those TIFF
files....I'm glad I don't have to use them! At least the RLE and EMF times
stayed the same - yay. Also remember that the GDI+ loop is still converting
the string to unicode 1000 times, so you should get better results by
converting the API declaration to use StrPtr.

    In case anyone is wondering, my hidden agenda is to provide possible
GDI+ solutions where GDI+ is not mentioned and GDI+ could really help out,
as I feel it deserves some merit and recognition. Some people don't know
what GDI+ does, or that it even exists!



Fri, 11 Feb 2005 12:51:04 GMT  
 "LoadPicture" Visual Basic replacement
Hello Nicola Taibi,

You can use 2Bitmap converter in your program:
http://batch.fcoder.com/2bitmap/index.htm

This program have MMX-optimized scale function for fast and quality
thumbnails creating.

2Bitmap will create thumbnails fast and you can use these thubmnails in your
program.

Regards,
Mikhael


Quote:
> Hi,

> I am working on thumbnail and I have seen that the visual basic
> function has a vary bad performance to read files in a very short
> time, BMP, GIF JPG (JPEG).

> I would like to use the Windows API (XP) to manipulate this files.

> Does anyone of you can give me any hint on which function I can use to
> read and load into the memory or object those files?

> Any help is greatly appreciated, thanks in advance, Nick

> Home page: http://geocities.com/whisky1767



Sun, 27 Feb 2005 21:48:38 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

2. "Is Visual BASIC basic?"

3. Colors problem of "LoadPicture()"

4. *** HELP: On LoadPicture("") ***

5. Cannot open the "Visual Basic-Editor"

6. AppleScript problems with "do Visual Basic"

7. Visual Basic and "mods"

8. "Visual Basic Programmers Needed"Ontario

9. Seeking Visual Basic 5 "mentors"!

10. "Visual" Basic

11. "MonthView" object in Visual basic

12. "SHOULD I DUMP VISUAL BASIC?"

 

 
Powered by phpBB® Forum Software