CADImage.SaveToStream clipRect
Posted: 22 Mar 2016, 18:02
Hi,
I could not find a way to set clipRect to cut a desired part of the image using the method CAD.Image.SaveToStream.
How do I set the clip rectangle to save only desired part of the image into the stream?
I have a negative coordinate values in my CADImage.Extends :
aimg.Extents {CADImport.DRect}
BadRect: {CADImport.DRect}
bottom: -1251.7798126050257
BottomRight: {CADImport.DPoint}
Center: {CADImport.DPoint}
Empty: {CADImport.DRect}
Height: 4101.949041876841
left: -890.57267136097767
right: 2853.1482046559349
top: 2850.1692292718153
TopLeft: {CADImport.DPoint}
Width: 3743.7208760169124
z1: -200.00000000000006
z2: 500.0
rectangle {CADImport.DRect}
BadRect: {CADImport.DRect}
bottom: 1138.389
BottomRight: {CADImport.DPoint}
Center: {CADImport.DPoint}
Empty: {CADImport.DRect}
Height: 297.0
left: 721.688
right: 1141.688
top: 1435.389
TopLeft: {CADImport.DPoint}
Width: 420.00000000000011
z1: 0.0
z2: 0.0
I succeeded using the code below :
What is better way to cut specific part of CADImage to create the picture preview ?
Thanks for answers.
I could not find a way to set clipRect to cut a desired part of the image using the method CAD.Image.SaveToStream.
How do I set the clip rectangle to save only desired part of the image into the stream?
I have a negative coordinate values in my CADImage.Extends :
aimg.Extents {CADImport.DRect}
BadRect: {CADImport.DRect}
bottom: -1251.7798126050257
BottomRight: {CADImport.DPoint}
Center: {CADImport.DPoint}
Empty: {CADImport.DRect}
Height: 4101.949041876841
left: -890.57267136097767
right: 2853.1482046559349
top: 2850.1692292718153
TopLeft: {CADImport.DPoint}
Width: 3743.7208760169124
z1: -200.00000000000006
z2: 500.0
rectangle {CADImport.DRect}
BadRect: {CADImport.DRect}
bottom: 1138.389
BottomRight: {CADImport.DPoint}
Center: {CADImport.DPoint}
Empty: {CADImport.DRect}
Height: 297.0
left: 721.688
right: 1141.688
top: 1435.389
TopLeft: {CADImport.DPoint}
Width: 420.00000000000011
z1: 0.0
z2: 0.0
I succeeded using the code below :
Code: Select all
Function PartOfImagePreview(ByVal filepath As String, ByVal rectangle As DRect) As System.Drawing.Bitmap
Dim img As System.Drawing.Bitmap = Nothing
Dim aImg As New CADImage
aImg = CADImage.CreateImageByExtension(filepath)
aImg.LoadFromFile(filepath)
aImg.DefaultColor = Color.White
aImg.BackgroundColor = Color.Black
Dim drc As System.Drawing.Rectangle
drc = New System.Drawing.Rectangle(aImg.Extents.left, aImg.Extents.top, aImg.Extents.Width, aImg.Extents.Height)
Dim ms As New System.IO.MemoryStream
Dim rc As System.Drawing.Rectangle
With rectangle
rc = New System.Drawing.Rectangle(Math.Abs(.left - aImg.Extents.left - 1), Math.Abs(aImg.Extents.top - .top - 1), .Width + 2, .Height + 2)
End With
aImg.SaveToStream(ms, ImageFormat.Bmp, aImg.Extents, drc)
Dim bmp As System.Drawing.Bitmap = System.Drawing.Bitmap.FromStream(ms)
img = bmp.Clone(rc, bmp.PixelFormat)
bmp.Dispose()
aImg.Dispose()
Return img
End Function
Thanks for answers.