Solved

How use MsPaint.exe in VB5 to open PNG picture and save it in BMP ?

Posted on 2008-06-25
21
2,909 Views
Last Modified: 2011-10-19
Hi,
I have a VB5 project that I use for display some  JPG and GIF images

FotoBrowser is an Image object on my form

I include  is a part of my VB code:
  ...i can display my PICTURES.
The problem is that PNG pictures are not supported.

So: MsPaint.exe is able to open PNG files and save it AS BMP files.

The question is: How can I do it in VB? VB can use ms  paint.exe as application, pass it a png file and have as result a bmp file?
Dim img As Picture

  fotoBrowser.Picture = Nothing

 

  Private Sub imageLoadAdjCenter(img As Picture)

   ...omissis load jpg or gif file in img

  End sub

  

  fotoBrowser.Picture = img

Open in new window

0
Comment
Question by:antares2001
  • 11
  • 7
21 Comments
 
LVL 22

Expert Comment

by:danaseaman
ID: 21867031
While MsPaint does support PNG it does not support 32-bit so you lose the alpha transparency channel. When you save as BMP you only get 24-bit image. That is the reason for using aicAlphaImage control which fully supports the nice looking Xp/Vista 32-bit PNG images.

You could use GDI+ to load a PNG and then convert to StdPicture but this won't work on Win98 without installing GDI+ on that Platform. aicAlphaImage control works on Win98 without the need to install GDI+.
0
 
LVL 1

Author Comment

by:antares2001
ID: 21872201
Ok,
but for my application, png converted in bmp is sufficient, (low level user public image viewer).
In any case I'm glad to undestood MsPaint interfacing in visual basic..... if is possible
thank
0
 
LVL 13

Expert Comment

by:game-master
ID: 21880472


good morning....

u can open image file using paint in vb

check this one...


Private Sub Command3_Click()
        Dim myPath As String
        myPath = "C:\xxx.bmp"
        Debug.Print myPath
        Shell "C:\WINDOWS\system32\mspaint.exe" & " " & myPath, vbMaximizedFocus
       
       
End Sub

this snippet will show the image in mspaint...

i hope this give u and idea...

game-master
0
 
LVL 1

Author Comment

by:antares2001
ID: 21881228
Hi,
this is the first part of my job....
then I have to save the file opened.....
In other word, visual basic have to do:
- run MsPaint
- open "picture.png" with MsPaint

case 1
- "save as" "picture.bmp" using MsPaint

or if case1 is impossible

case 1
- select all "picture" from MsPaint
- paste "picture" in vb image control  (image1.picture = "mspaint-picture)

is possible that?
regards

 
0
 
LVL 13

Expert Comment

by:game-master
ID: 21881259


why to do u need to saveas the image on the paint?

if your goal is to saveas the image to the specific location,
well it think u can use the filesystemobject to copy the specific image
to your desired location..
and then showed it using the mspaint...


game-master
0
 
LVL 1

Author Comment

by:antares2001
ID: 21881295
Sorry,
I try to be more clear:
I have a VB application that was written time ago from a consultant. It shows BMP,  JPG and GIF pictures in special mode... but PNG are not supported, because IMAGE control of VB5/6 don't support PNG.

MsPaint is able to open PNG and SAVE AS  BMP 24 bit.

My goal is to made a simple modify to my VB application with a new procedure that "preload PNG by way of MsPaint (or other way), save it AS BMP and then continue my application with normal run.
 
I'm  novice programmer, and this is a simple way... but I can't do it.
More ideas?
0
 
LVL 13

Accepted Solution

by:
game-master earned 120 total points
ID: 21896128
Private Sub Command3_Click()
        Dim myPath As String
        myPath = "C:\xxx.bmp"
        Debug.Print myPath
        Shell "C:\WINDOWS\system32\mspaint.exe" & " " & myPath, vbMaximizedFocus
       
       
End Sub
0
 
LVL 1

Author Comment

by:antares2001
ID: 21897467
game-master,
I 'm running on your path and my job is in progress, but not ended....
please help me to save MsPaint opened file ( complete ?????? code)
Thank you


' MAIN

' Open a PNG image using MsPaint (ok)

'_______ this command is same to:  Run MsPaint -> Open FIle C:\italy1.png)

          call OpenPngInMsPaint()
 

' Save MsPaint opened picture AS BMP format 

'______ (this command is same to:  From running MsPaint -> Save As C:\italy1.bmp)

         call SaveMsPaintOpenedFileAsBmp()

' END OF MAIN
 

' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Private Sub OpenPngInMsPaint()

        Dim myPath As String

        myPath = "C:\italy1.png"

        Debug.Print myPath

        Shell "C:\WINDOWS\system32\mspaint.exe" & " " & myPath, vbMaximizedFocus

End Sub

' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Private Sub SaveMsPaintOpenedFileAsBmp()

                     ??????????

                     ??????????

                     ??????????

                     ??????????

End Sub

' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Open in new window

0
 
LVL 1

Author Comment

by:antares2001
ID: 21897477
A file png format
italy1.PNG
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

by:antares2001
ID: 21897506
The file PNG opened from MsPaint and saved as BMP (from windows  - I have to do it from VB)
italy1.bmp
0
 
LVL 13

Expert Comment

by:game-master
ID: 21897537


good afternoon...

i try this code and works fine on me...


Private Sub Command3_Click()
        Dim myPath As String
        myPath = "C:\italy1.PNG"
        Debug.Print myPath
        Shell "C:\WINDOWS\system32\mspaint.exe" & " " & myPath, vbMaximizedFocus
        Debug.Print "C:\WINDOWS\system32\mspaint.exe" & " " & myPath & "xxx.bmp"
       

        'i use this code to copy the png file to my "Drive C" and saved the image as "myTest.bmp"

        FileCopy myPath, "c:\myTest.bmp"

       'i just used this message box to know if the program runs through my code.
       
        MsgBox "OK"  
       
End Sub


i hope will give u some idea..

game-master
0
 
LVL 1

Author Comment

by:antares2001
ID: 21897601
Sorry!
Your code create a file xxx.bmp ... but this is a png file.
italy1.png size 21kb - header 0PNG.......


xxx.bmp size 21kb - header 0PNG.......

If I do it fro ms paint with command SAVE AS BMP I have this:
italy1.bmp size 262kb - header BMî.........
0
 
LVL 13

Expert Comment

by:game-master
ID: 21897667


yes...

i been working for your question...
i am also new to that instance...

lets both work it out...


game-master
0
 
LVL 1

Author Comment

by:antares2001
ID: 21915577
Hi all
more info?
0
 
LVL 13

Expert Comment

by:game-master
ID: 21922527


good morning...

i'm sorry...
i was out on the office for how many days..


i heard u can use the api function "shellexecute"

here is the declaration..

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


'this is a sample way to use it..

sub <your procedure name for example>
ShellExecute Me.hwnd, vbNullString, "mailto:KPDTeam@Allapi.net", vbNullString, "C:\", SW_SHOWNORMAL
end sud
0
 
LVL 1

Author Comment

by:antares2001
ID: 21923070
Hi,
I'm in confusion...      ;-()

Are you rure that this sample "make" SAVE AS BMP from MsPaint?
0
 
LVL 13

Expert Comment

by:game-master
ID: 21930455


what i am imposing on my posted comment is that,
that is how to use the shellexecute...but that is not the
code to save a bitmap...
0
 
LVL 1

Assisted Solution

by:antares2001
antares2001 earned 120 total points
ID: 21943027
... in other wods is not possible do it?
0
 
LVL 1

Author Comment

by:antares2001
ID: 21963228
Sorry, nobody answer my question:
How use MsPaint.exe in VB5 to open PNG picture and save it in BMP ?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now