Solved

How to resize picture in file with VB6 and keep transparent colour

Posted on 2011-02-20
7
1,380 Views
Last Modified: 2012-05-11
Hi Experts!

I need a ActiveX component or code which to use with VB6 and it should works with graphic files and to have these futures:
1.      To make resize of pictures in format BMP, JPG, GIF, PNG is a plus
2.      It should be able to keep transparent color of GIF file

Till now I found PowerResize of Mark, it works fine but do not keep transparent colour.
0
Comment
Question by:dvplayltd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34942362
UNTESTED WITH GIF

Try this simple code.

Please insert a Picture box control in your form.

This code will re size the image and create 9 copies. You may change the code to get relevant copies.

Private Sub Command1_Click()
    Dim pic1 As Picture
    
    '~~> Your Picture Path here
    Set pic1 = LoadPicture("C:\MyPic.bmp")
    Picture1.Visible = False
    '~~> Make Form Scalemode = Pixels
    Picture1.Container.ScaleMode = vbPixels
    '~~> Make PictureBox Scalemode = Pixels
    Picture1.ScaleMode = vbPixels
    Picture1.BorderStyle = 0
    Picture1.AutoRedraw = True
    
    '~~> (Create a Saves Folder in your App.Path or change to another valid folder as last parameter)
    ResizePics Me.Picture1, pic1, -20, 20, -20, 20, 20, 20, App.Path & "\saves\"
End Sub


Private Sub ResizePics(pBox As PictureBox, pPic As Picture, xFrom As Long, Xto As Long, _
                                                                         yFrom As Long, yTo As Long, _
                                                                         xStep As Long, yStep As Long, _
                                                                         pSavePath As String)
    Dim PicWidth As Long, PicHeight As Long, i As Long, j As Long

    PicWidth = pBox.ScaleX(pPic.Width, vbHimetric, vbPixels)
    PicHeight = pBox.ScaleY(pPic.Height, vbHimetric, vbPixels)
    
    For i = PicWidth + xFrom To PicWidth + Xto Step xStep
        For j = PicHeight + yFrom To PicHeight + yTo Step yStep
            pBox.Width = i
            pBox.Height = j
            pBox.Cls
            pBox.PaintPicture pPic, 0, 0, i, j
            SavePicture pBox.Image, pSavePath & "Sample (" & i & " x " & j & ").bmp"
        Next
    Next
End Sub

Open in new window


Sid
0
 

Author Comment

by:dvplayltd
ID: 34942569
I have a code which change the size of picture, BUT MY QUESTION IS TO WORKS with .gif and with transperant colour!
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 34943837
try this link:
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 500 total points
ID: 34943854
try this link:
     http://www.chestysoft.com/imagefile/instructions.pdf


11.3. Visual Basic
For best results import the csImageFile type library into VB by selecting "Project" from the menu bar,
then "References". The dialogue box will then show available type libraries. Scroll down to
"csImageFile Library", check the box and click OK. This will add the "Manage" class from
csImageFile to the Object Browser, making it available for early binding.
To create an instance of the object called "Image" use the following code:
Dim Image As Manage
Set Image = CreateObject("csImageFile.Manage")
Displaying an image from csImageFile in a VB picture box is not simple as it involves an API call to
create a bitmap. There is a description of this and some sample code on our web site at:
www.chestysoft.com/imagefile/vbimage.asp
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 34943891

Excel seems to have the capabilities you are looking for.  See this link:
       http://office.microsoft.com/en-us/excel-help/about-drawing-objects-and-pictures-HP005236498.aspx
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 34943927
see also this link:
           http://www.informatik.com/tiffdll.html
0
 

Author Closing Comment

by:dvplayltd
ID: 34995724
The library is not free.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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