OPENNETCF - ImageUtils - Rotate - How to..?

G

Guest

Hi,

I am completly new to the opennetcf and my question is how I can do the
following things under VB.NET:

- open an image (transparent) from a local path...don't know how to do under
opennetcf

- rotate the image and draw it transparent on a picturebox image

I found the code for c# but I am not really familiar with it - this is my
translation:

Dim img As OpenNETCF.Drawing.Imaging.IImage

Dim factory As OpenNETCF.Drawing.Imaging.IImagingFactory = New
OpenNETCF.Drawing.Imaging.ImagingFactory
factory.CreateImageFromStream(AppPath & "\star_2_5.gif", img)

OpenNETCF.Drawing.Imaging.ImageUtils.Rotate(img, 30)


Dim hDC As IntPtr = myGraphics.GetHdc
Dim rc As OpenNETCF.Drawing.Imaging.RECT =
OpenNETCF.Drawing.Imaging.RECT.FromXYWH(240, 240, 200, 200)
img.Draw(hDC, rc, Nothing)

myGraphics.ReleaseHdc(hDC)

-------But I get a NoReferenceException

Please help me.....juvi
 
A

Alex Feinman [MVP]

You need to check the integer value retunred by the call to CreateImageFromStream - if it's not 0 there was an error:

Imports OpenNETCF.Drawing.Imaging

Public Class Form1
Dim img As IImage
Dim bm As Bitmap
Dim factory As New ImagingFactory
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ret As Integer = factory.CreateImageFromStream(New StreamOnFile("\test.jpg"), img)
If ret = 0 Then
'Uncomment this to use Bitmap

'Dim imgBitmap As IBitmapImage
'ret = factory.CreateBitmapFromImage(img, Width, Height, Imaging.PixelFormat.Format16bppRgb565, InterpolationHint.InterpolationHintBilinear, imgBitmap)
'If (ret = 0) Then
' bm = ImageUtils.IBitmapImageToBitmap(imgBitmap)
'End If
Else
MessageBox.Show(String.Format("Failed to load the image - {0:X}", ret))
End If
End Sub

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'MyBase.OnPaint(e)
If Not img Is Nothing Then
Dim hdc As IntPtr = e.Graphics.GetHdc()
img.Draw(hdc, New RECT(0, 0, Width, Height), Nothing)
e.Graphics.ReleaseHdc(hdc)
End If
End Sub

End Class
 
G

Guest

Thank you for your reply.....but how can I now rotate the image before
drawing it?
juvi
 
A

Alex Feinman [MVP]

To rotate:
Create IBitmapImage from an IImage (see commented code below)
Cast IBitmapImage to IBasicBitmapOps:
Dim bo as IBasicBitmapOps = CType(imgBitmap, IBasicBitmapOps)
Use IBasicBitmapOps.Rotate( 90, InterpolationHint.InterpolationHintDefault, imgBitmap)
Remember that you can rotate only by 90/180/270 degrees. Windows CE does not support other angles
 
Top