Solved

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

Posted on 2011-02-20
7
1,322 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
  • 4
  • 2
7 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
Comment Utility
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
Comment Utility
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
Comment Utility
try this link:
0
Highfive Gives IT Their Time Back

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!

 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 500 total points
Comment Utility
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
Comment Utility

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
Comment Utility
see also this link:
           http://www.informatik.com/tiffdll.html
0
 

Author Closing Comment

by:dvplayltd
Comment Utility
The library is not free.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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 …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

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

9 Experts available now in Live!

Get 1:1 Help Now