By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

Image Resize

P: n/a
Hi, I know I seem to have the really complicated questions, but I guess
that's why I'm here. This is a little verbose, only because I've been
trying to crack this for a week now.

Your help would be appreciated.

I've been trying numerous ways to resize images, as I want to make store
thumbnails, not full images in my database.

-----------------------------------------------------------------------------
Method 1: So I tried the VB way -
that is to use LoadPicture to a picture box, resize the box, then copy to
another box and then 'SavePicture Picture2.Picture,strFilename'

That doesn't work as the controls in Access are somewhat different. So I
tried

----------------------------------------------------------------------------
Method 2: Access Image and OLEBoxes. -
image1.picture = strFilename

That doesn't work because the picture property is only a filename, I've
tried 'SavePicture image1.PictureData', but it won't work.

-------------------------------------------------------------------------------
Method 3: The IPicture Object
Dim imgPicture as Object
Set imgPicture = LoadPicture(filename)

But then I can't resize the image. Once upon a time I think LoadPicture
allowed you to use incoming dimensions stdole.StdFunctions.LoadPicture, but
when I did the SavePicture, the dimensions never changed, and in fact the
file size grew bigger due to loss of compression.

------------------------------------------------------------------------------
All Up: this is what I have so far:
Sub ResizeImageWithAspect(strFilename As String, strOutputFilename As
String, intNewWidth As Integer, intNewHeight As Integer)
On Error GoTo Err_Sub
Dim imgOriginal As Object
Dim ctl As Control ' I can't get image data back if I save image to
control
Dim sglAspect As Single
Dim intTempHeight As Integer

Set imgOriginal = LoadPicture(strFilename)
sglAspect = imgOriginal.Height / imgOriginal.Width
intTempHeight = intNewWidth * sglAspect

If intTempHeight intNewHeight Then
sglAspect = imgOriginal.Width / imgOriginal.Height
intNewWidth = intNewHeight * sglAspect
Else
intNewHeight = intTempHeight
End If
Set imgOriginal = LoadPicture(strFilename)

''''''''''''''
'Image Resize needed here
''''''''''''''''

SavePicture imgOriginal, strOutputFilename
Exit_Sub:
DoCmd.Close acForm, "frmWebPictureResize"
Set imgOriginal = Nothing
Exit Sub
Err_Sub:
MsgBox Err.Number & ": " & Err.Description
' Resume Exit_Sub
Resume Next
End Sub

-----------------------------------------------------------------------------------
Can anyone tell me how to resize an image in MS-Access? Thanks in advance.

Jan 15 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Dominic I am just heading out the door but I can get you pointed in the
right direction. There is a vbPictureBox class on my site. It is written in
native VBA and contains a resize method.
http://www.lebans.com/imageclass.htm
ImageClass has been replaced by the PictureBoxA97 project. A standard Image
control is wrapped within a class to allow the control to resemble the
standard Visual Basic PictureBox control. Simple drawing methods are
directly supported as is Text output with rotation. A handle to a Device
Context is exposed to allow the developer to use the full range of Graphic
API's. Also supports Screen Grabs, Copy to Clipboard and Save Image control
to a disk Bitmap file. Here is the Access 2000 version, PictureBoxA2K.zip
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Dominic Vella" <do***********@optusnet.com.auwrote in message
news:47***********************@news.optusnet.com.a u...
Hi, I know I seem to have the really complicated questions, but I guess
that's why I'm here. This is a little verbose, only because I've been
trying to crack this for a week now.

Your help would be appreciated.

I've been trying numerous ways to resize images, as I want to make store
thumbnails, not full images in my database.

-----------------------------------------------------------------------------
Method 1: So I tried the VB way -
that is to use LoadPicture to a picture box, resize the box, then copy to
another box and then 'SavePicture Picture2.Picture,strFilename'

That doesn't work as the controls in Access are somewhat different. So I
tried

----------------------------------------------------------------------------
Method 2: Access Image and OLEBoxes. -
image1.picture = strFilename

That doesn't work because the picture property is only a filename, I've
tried 'SavePicture image1.PictureData', but it won't work.

-------------------------------------------------------------------------------
Method 3: The IPicture Object
Dim imgPicture as Object
Set imgPicture = LoadPicture(filename)

But then I can't resize the image. Once upon a time I think LoadPicture
allowed you to use incoming dimensions stdole.StdFunctions.LoadPicture,
but when I did the SavePicture, the dimensions never changed, and in fact
the file size grew bigger due to loss of compression.

------------------------------------------------------------------------------
All Up: this is what I have so far:
Sub ResizeImageWithAspect(strFilename As String, strOutputFilename As
String, intNewWidth As Integer, intNewHeight As Integer)
On Error GoTo Err_Sub
Dim imgOriginal As Object
Dim ctl As Control ' I can't get image data back if I save image to
control
Dim sglAspect As Single
Dim intTempHeight As Integer

Set imgOriginal = LoadPicture(strFilename)
sglAspect = imgOriginal.Height / imgOriginal.Width
intTempHeight = intNewWidth * sglAspect

If intTempHeight intNewHeight Then
sglAspect = imgOriginal.Width / imgOriginal.Height
intNewWidth = intNewHeight * sglAspect
Else
intNewHeight = intTempHeight
End If
Set imgOriginal = LoadPicture(strFilename)

''''''''''''''
'Image Resize needed here
''''''''''''''''

SavePicture imgOriginal, strOutputFilename
Exit_Sub:
DoCmd.Close acForm, "frmWebPictureResize"
Set imgOriginal = Nothing
Exit Sub
Err_Sub:
MsgBox Err.Number & ": " & Err.Description
' Resume Exit_Sub
Resume Next
End Sub

-----------------------------------------------------------------------------------
Can anyone tell me how to resize an image in MS-Access? Thanks in
advance.

Jan 15 '08 #2

P: n/a

"Dominic Vella" <do***********@optusnet.com.auschreef in bericht news:47***********************@news.optusnet.com.a u...
No, I was hoping the database would be self-contained without having to use
any references unless called by the Declare function or the CreateObject
method.

Maybe there is a way to create a Paintbrush Object, resize and save that
somehow? I still can't find the way. I'd use BltBit (or somethin like
that) stuff on the images, but I can't find any hwnd handles on any of the
MS-Access controls (not that hwnd handles are ever used by Visual Basic
Programmers).

Thanks for the reply anyway.
Dominic
You only need to download and install the program.
(Include the VB Com object)

I think it's fabulous for working with lots of images from within Access!
(I just recently discovered it ...)

You can use late binding like
Sub TestIM()
Dim objIM As Object
Dim imgResult

Set objIM = CreateObject("ImageMagickObject.MagickImage.1")
imgResult = objIM.Convert("C:\bill_meets_gorilla_screen.jpg", "-thumbnail", 300, "C:\billthumb.jpg")
'This converts the original image to a smaller one of max 300 pixels

If Err.Number <0 Then
MsgBox "Error converting image"
Else
MsgBox "Conversion OK"
End If
Set objIM = Nothing
End Sub

I am not trying to convince you but ... ;-)
With a few lines of code you could handle a whole directory (invDir) of images, fully automated from within Access !!

'First, read a filelist in an array called aFileList()
---
For i = 0 To UBound(aFileList) - 1
imgResult = objIM.Convert(invDir & aFileList(i), "-thumbnail", "250x250", invDir & "Thumbs\" & aFileList(i))
'Convert all images and put them in a subdir called 'Thumbs'
Next i
---

Arno R
Jan 15 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.