Link to home
Start Free TrialLog in
Avatar of apmanzojr
apmanzojr

asked on

Title: How do I programmatically rezise and image in MS access using vba.

Title: How do I programmatically rezise and image in MS access using vba.

I have an inquiry in regarding image resize in Access vba. First is, is it possible to resize a desire size in access? I have a problem in making it works.

I have a form that has textbox, cmdbutton, and image control on my form.  I used textbox to display the path command button to activate commondialog box (API from microsoft) and Image to display the image after the size has been manipulated.

On my code I did this.

dim tempImage as Image
Dim path as String

Me!txtboxt = LaunchCD(ME)--> I activate the common dialog box. passing the path
path = Me.txtboxt.value --> setting the path of the selected image from the directory

If I wanted to display the image that I selected from the directory I do this.

Me.ImageControl.Picture = path

The problem is I wanted to resize the image first before displaying it. I did this

Set tempImage = new Image --> does not work error say can't create activex component.
I try
Set tempImage = Me.txtboxt --> type mismatched

I try a file object but it's still giving me the same error type mismatched.

with my file object I did this

Dim fs, f

set fs = createObject("Scripting.FileSystemObject")
set f = getFile(path)

but the problem is I can not still use my tempimage varialbe to manipulate my selected image. I am getting the feeling the there is no way to make this work. If there is how do I manipulate the size of my image? If my form Image is like height = 5inches and width is 6 inches. Please help I need this for my work?

Thank you in advance.

Alex
 



ASKER CERTIFIED SOLUTION
Avatar of ee_rlee
ee_rlee
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of apmanzojr
apmanzojr

ASKER

Hi guys,

Thanks for the reply sorry I I just got back right now I just woke up since I know that when I post this question it was 1 am in the morning. anyways, I tried the codes that you guys suggested but what is happening is it makes my image form expand depending on my size of the image that I selected . Meaning that If I selected a very big image It makes my image control on the form big too. What I want is to be able to fit any selected image to my Image control. Example if my image control (on the form) size is height = 2 inc and width is 3  I want my image (selected file) to fit on the image control on the form.  Not to expand it or crop it. Assuming the image that I selected is bigger on my image control on my form. any idea?

the reason why I use textbox and image control is, I wanted to store an image to a table and the path to a seperate table in the database because If I use OLE object it takes alot of space

Thanks
Setting the .SizeMode property to 1 as ee_rlee suggested should make the picture fit the control.
yes, first load the image. then set the desired size of the image control. the set sizemode to 1.
Hello,

Thanks for the reply, so do you mean that it will automatically set my image (image that I selected from common dialog box) to the desired image that I want? So how about if I wanted to select another image again?
'On cmdClick event
 Dim ImageControl As New Image
   
    Dim path As String
   

    Me!Text1 = LaunchCD(Me)
   
    path = Me.Text1
    'Me.Image3.SizeToFit = 1
    Me.Image3.Picture = path


'On form load
Private Sub Form_Load()
Me.Image3.Height = Me.Image3.Height * 1.5
Me.Image3.Width = Me.Image3.Width * 1.5

End Sub
Option Compare Database

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

Function LaunchCD(strform As Form) As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim sFilter As String
    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = strform.Hwnd
    sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
      "JPEG Files (*.JPG)" & Chr(0) & "*.JPG" & Chr(0)
    OpenFile.lpstrFilter = sFilter
    OpenFile.nFilterIndex = 1
    OpenFile.lpstrFile = String(257, 0)
    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
    OpenFile.lpstrFileTitle = OpenFile.lpstrFile
    OpenFile.nMaxFileTitle = OpenFile.nMaxFile
    OpenFile.lpstrInitialDir = "C:\"
    OpenFile.lpstrTitle = "Select a file using the Common Dialog DLL"
    OpenFile.flags = 0
    lReturn = GetOpenFileName(OpenFile)
        If lReturn = 0 Then
            MsgBox "A file was not selected!", vbInformation, _
              "Select a file using the Common Dialog DLL"
         Else
            LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
         End If
End Function
                   
What happen here the image it not resizing it crops to my desired size. I wanted to shrink the image (the one that I selected from the directory basically manipulate the image height and width before display in the form or storing in the database) and enlarge the image according to the size of my image control on the form assuming the height of my image is 5 inches and the width is 5inches too.
set sizemode to 1 after setting the image path

Me.Image3.Picture = path
Me.Image3.SizeMode = 1
Thank you for the reply