Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Rotate jpg/tif

Posted on 2004-04-24
7
Medium Priority
?
937 Views
Last Modified: 2013-11-19
I have an Image box in a form, whose image is populated in VBA as follows:

Image26.Picture = LoadPicture("c:\hi.jpg")

How can I get it to load rotated 90 degrees?

I am aware that http://support.microsoft.com/default.aspx?scid=KB;en-us;q186260 allows a bitmap to be rotated 90 degrees, but it doesn't work for jpgs or tifs.

Many thanks.

0
Comment
Question by:PhillipBurton
[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
  • 2
  • 2
  • 2
7 Comments
 
LVL 13

Expert Comment

by:imarshad
ID: 10909231
Why do you want to use an "Image Box" and why not a "Picture Box"..... The image box donot have hDC which severely limits the use of API to rotate the image.......

0
 
LVL 5

Author Comment

by:PhillipBurton
ID: 10911038
If I could use a PictureBox, who would I do the rotation?
0
 
LVL 7

Accepted Solution

by:
Burbble earned 1600 total points
ID: 10912261
You mind find use in the code here:

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=4583&lngWId=1

To avoid the little "spiral" effect of drawing an image at an angle, remove the t% = DoEvents() line in the bmp_rotate() sub, and set Picture2.AutoRedraw = True.

You can use any angle, just change the Theta value of this line in Command3_Click() sub...

Call bmp_rotate(Picture1, Picture2, 3.14 / 4)

...to whatever angle you want (in radians -- i.e. 3.14 / 2 = 90°).

-Burbble
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Assisted Solution

by:imarshad
imarshad earned 400 total points
ID: 10969449
You can also use this code
Add a Picture Box control on the form and add a JPG onto the Picture  box and paste the following code

Private Const DIB_RGB_COLORS = 0 '  color table in RGBs
Private Type RGBQUAD
        rgbBlue As Byte
        rgbGreen As Byte
        rgbRed As Byte
        rgbReserved As Byte
End Type
Private Type BITMAPINFOHEADER '40 bytes
        biSize As Long
        biWidth As Long
        biHeight As Long
        biPlanes As Integer
        biBitCount As Integer
        biCompression As Long
        biSizeImage As Long
        biXPelsPerMeter As Long
        biYPelsPerMeter As Long
        biClrUsed As Long
        biClrImportant As Long
End Type
Private Type BITMAPINFO
        bmiHeader As BITMAPINFOHEADER
        bmiColors As RGBQUAD
End Type
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function SetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long

Private Sub Form_Load()
'Dim fn As String
'fn = App.Path
'If Right$(fn, 1) <> "\" Then fn = fn & "\"
'fn = fn & "vb.jpg"
picInitial = LoadPicture() 'Enter the Path of Picture to be rotated here
picRot = picInitial
picRot.Move 0, 0, picInitial.Height, picInitial.Width
End Sub

Private Sub picInitial_Click()
Dim bmi As BITMAPINFO
Dim bits() As RGBQUAD
Dim x As Long, y As Long
Dim aRot() As RGBQUAD
Dim mx As Long, my As Long
 
'//Redim our array to the size of the picturebox
mx = picInitial.ScaleWidth - 1
my = picInitial.ScaleHeight - 1
ReDim bits(mx, my)
ReDim aRot(my, mx)
With bmi.bmiHeader
    .biSize = 40
    .biPlanes = 1
    .biBitCount = 32
    .biCompression = 0
    .biClrUsed = 0
    .biClrImportant = 0
    .biSizeImage = (mx + 1) * (my + 1)
    .biWidth = mx + 1
    .biHeight = my + 1
End With
x = GetDIBits(picInitial.hdc, picInitial.Image.Handle, 0, my + 1, bits(0, 0), bmi, DIB_RGB_COLORS)
For x = 0 To mx
    For y = 0 To my
        aRot(my - y, x) = bits(x, y)
    Next y
Next x
With bmi.bmiHeader
    .biSize = 40
    .biPlanes = 1
    .biBitCount = 32
    .biCompression = 0
    .biClrUsed = 0
    .biClrImportant = 0
    .biSizeImage = (mx + 1) * (my + 1)
    .biWidth = my + 1
    .biHeight = mx + 1
End With
x = SetDIBits(picRot.hdc, picRot.Image.Handle, 0, bmi.bmiHeader.biHeight, aRot(0, 0), bmi, DIB_RGB_COLORS)
picInitial.Visible = False
picRot.Refresh
End Sub
0
 
LVL 5

Author Comment

by:PhillipBurton
ID: 11263970
Burbble's solution seems quick, if one eplaces pic1hDC%, pic1hDC% with pic1hDC&, pic1hDC&.

Whilst  imarshad's solution looks good, it seems to take ages with a fairly big graphic.

Thanks to everyone who helped.
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11264861
Glad you got it working, thanks for the points.

-Burbble
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…
Suggested Courses

664 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