How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic??
How do I save this GDIplus graphic?? How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
Go Back  Xtreme Visual Basic Talk > > > How do I save this GDIplus graphic??


Reply
 
Thread Tools Display Modes
  #1  
Old 01-04-2011, 02:13 AM
neosonic neosonic is offline
Newcomer
 
Join Date: Jan 2011
Posts: 7
Unhappy How do I save this GDIplus graphic??


Hi.

I am using the GDIplus to rotate my picture and I got the code example as follows:

Private Sub DrawRotated()
Dim graphics As Long, img As Long, pen As Long
Dim lngHeight As Long, lngWidth As Long

' Initializations
Call GdipCreateFromHDC(Me.hdc, graphics) ' Initialize the graphics class - required for all drawing
Call GdipLoadImageFromFile(StrConv(App.path & "\GrapeBunch.bmp", vbUnicode), img)

' Get the image height and width
Call GdipGetImageHeight(img, lngHeight)
Call GdipGetImageWidth(img, lngWidth)

' This will rotate EVERYTHING!
' There are several rotation APIs available for you!
Call GdipRotateWorldTransform(graphics, 45, MatrixOrderAppend)

' Make sure to provide a good x,y starting point!
Call GdipDrawImageRect(graphics, img, 200, -150, lngWidth, lngHeight)

SavePicture picGrapes.image, App.path & "\GrapeRotated.png"\

' Cleanup
Call GdipDisposeImage(img)
Call GdipDeleteGraphics(graphics)
End Sub

My problem is:

1. I don't know how to provide a good x, y starting point.
2. My bigger problem is: SavePicture picGrapes.image only give me the blank white picture. I want the rotated grape picture...

Please help me... thanks
Reply With Quote
  #2  
Old 01-04-2011, 12:45 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

Replace the line
Code:
'SavePicture picGrapes.image, App.path & "\GrapeRotated.png"\
with
Code:
'  Get the CLSID of the PNG encoder.
Dim encoderClsid As CLSID
Call GetEncoderClsid("image/png", encoderClsid)

Dim stat As Long
stat = GdipSaveImageToFile(img, StrConv(App.path & "\GrapeRotated.png", vbUnicode), _
                           encoderClsid, ByVal 0)

Last edited by mms; 01-04-2011 at 01:02 PM.
Reply With Quote
  #3  
Old 01-05-2011, 10:36 PM
neosonic neosonic is offline
Newcomer
 
Join Date: Jan 2011
Posts: 7
Default

Hi mms for replying my message.
By replacing that line, I'm able to save the image but.. not the rotated image..
So basically the saved image will be the same as GrapeBunch.bmp.

Since I have these lines:

' This will rotate EVERYTHING!
' There are several rotation APIs available for you!
Call GdipRotateWorldTransform(graphics, 45, MatrixOrderAppend)

' Make sure to provide a good x,y starting point!
Call GdipDrawImageRect(graphics, img, 200, -150, lngWidth, lngHeight)

I can see the image is rotated by 45 degree in the picturebox. (It is not permanent though, once I minimize the form, the picturebox is back to blank). I don't know how to save as the .png or .jpg file....

I have tried using:
picturebox.Picture = picturebox.Image
SavePicture picturebox.Picture, App.path & "\GrapeRotated.png"\

I have no clue
Reply With Quote
  #4  
Old 01-05-2011, 11:57 PM
OnErr0r's Avatar
OnErr0rHow do I save this GDIplus graphic?? OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #5  
Old 01-06-2011, 12:00 AM
OnErr0r's Avatar
OnErr0rHow do I save this GDIplus graphic?? OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

hrm.. looks like I made a change to my locally saved zip file:

Code:
Private Sub Form_Click() ' CLICK THE FORM! :P Dim sngAngle As Single ' Note: Clone is not needed if loading from file ' In fact, it will cause a GDI+ error on saving For sngAngle = 0 To 360 Step 8 Set saveBmp = New cBitmap 'saveBmp.CreateFromClone IMG_SIZE, IMG_SIZE, bitmap.Handle, PixelFormat32bppARGB saveBmp.CreateFromScan0 IMG_SIZE, IMG_SIZE, bitmap.Width * 4, PixelFormat32bppARGB, 0 ' graphics.GetGraphicsContext bitmap.Handle graphics.GetGraphicsContext saveBmp.Handle graphics.RotateTransform sngAngle graphics.TranslateTransform IMG_SIZE \ 2, IMG_SIZE \ 2, MatrixOrderAppend graphics.DrawImageRectI bitmap.Handle, -IMG_SIZE \ 2, -IMG_SIZE \ 2, IMG_SIZE, IMG_SIZE saveBmp.SaveToFile "c:\rotate" & Right$("00" & CStr(sngAngle), 3) & ".jpeg", gdip.EncoderGuid(gdip.ExtensionExists("*.jpeg")), 0 Set saveBmp = Nothing graphics.ResetTransform Next sngAngle End Sub
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #6  
Old 01-06-2011, 10:48 PM
neosonic neosonic is offline
Newcomer
 
Join Date: Jan 2011
Posts: 7
Default

Your zip works wonderfully thanks a lot.
Yes, you made changes on it, but it still do the job
Reply With Quote
  #7  
Old 01-07-2011, 01:10 AM
neosonic neosonic is offline
Newcomer
 
Join Date: Jan 2011
Posts: 7
Default

Hi, I notice for every rotated image, I still see the original image in the background, how do we "clean" it, so it will be only the rotated image that's visible?

another thing is:
I'm still trying to put my rotated image in the picturebox.
Is there anyway that we can choose the good starting x and y as stated in my first post in these thread?
Reply With Quote
  #8  
Old 01-10-2011, 02:11 AM
neosonic neosonic is offline
Newcomer
 
Join Date: Jan 2011
Posts: 7
Default

Hi, I have solved the starting x and y, once I put the gdiptranslateworldtransform, it works fine
Reply With Quote
Reply

Tags
gdiplus, graphics


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
How do I save this GDIplus graphic?? How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic?? How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
 
How do I save this GDIplus graphic??
How do I save this GDIplus graphic??
 
-->