OK for someone like me on here in desperate situation - .png
works for
mysterious reasons. For other formats I still have black
images. I am
hoping for some help and clues on other formats.
Thanks.
Veda.
On Jan 20, 1:53 pm, veda <kedar.hardi... gmail.com> wrote:
> Hi ,
> I am new to vb.net and need urgent help on the
following -
>
> I am drawing lines/curves in apictureboxwith white
background. After
> I am done want to save theimagein jpg. However when I
do that theimagehasblackbackground and I loose text that I
write in the
> picturebx. I want a jpg file that looks like
myimageonpicturebox
> i.e white background and colors of lines/curves/text
intact.
>
> I tried googling but didn't understand what I saw. My
attempt is given
> below. Please help asap.
> Thanks in advance
> Veda.
>
> ====
> Private Sub SavePictureToolStripMenuItem_Click(ByVal
sender As
> System.Object, ByVal e As System.EventArgs) Handles
> SavePictureToolStripMenuItem.Click
>
> Dim MYPATH As String
> Dim FILENAME As String
> MYPATH =
My.Computer.FileSystem.CurrentDirectory
> FILENAME = MYPATH &
"L2DImage.jpg"
> '' Get a Bitmap.
> 'Dim bm As Bitmap '= picImage.Image
> Dim pic AsPictureBox= Me.PictureBox1
>
> SaveImage(pic, FILENAME)
>
> MessageBox.Show("Imagesaved as
L2DImage.jpg", "ScreenImage
> Save")
> End Sub
> Sub SaveImage(ByVal pb AsPictureBox, ByVal sFile As
String)
> Dim bmp As New Bitmap(pb.Width, pb.Height)
> Dim g As Graphics = Graphics.FromImage(bmp)
> Dim pe As New PaintEventArgs(g, New
Rectangle(Point.Empty,
> bmp.Size))
> Me.InvokePaint(pb, pe)
> Dim fmt As Imaging.ImageFormat
> Dim lFile As String = sFile.ToLower
>
> '' InvertImagecolors
> ''Dim X As Integer
> ''Dim Y As Integer
> ''Dim r As Integer
> ''Dim g1 As Integer
> ''Dim b As Integer
>
> ''For X = 0 To bmp.Width - 1
> '' For Y = 0 To bmp.Height - 1
> '' 'r = 255 - bmp.GetPixel(X, Y).R
> '' 'g1 = 255 - bmp.GetPixel(X, Y).G
> '' 'b = 255 - bmp.GetPixel(X, Y).B
> '' bmp.SetPixel(X, Y, Color.FromArgb(r,
g1, b))
> '' Next Y
> ''Next X
> 'Dim cm As New Imaging.ColorMap
> ' ''Black- old color
> 'cm.OldColor = Color.FromArgb(255, _
> ' 0, _
> ' 0, _
> ' 0)
> '' White new color
> 'cm.NewColor = Color.FromArgb(255, _
> ' 255, _
> ' 255, _
> ' 255)
> 'Dim remap_table() As Imaging.ColorMap =
> 'Dim image_attr As New Imaging.ImageAttributes
> 'image_attr.SetRemapTable(remap_table, _
> ' Imaging.ColorAdjustType.Bitmap)
>
> ' ''Dim bm_src As Bitmap = bmp
> ' ''Dim bm As New Bitmap(bm_src.Width,
bm_src.Height)
> ''Dim gr As Graphics = Graphics.FromImage(bm)
> 'Dim rect As Rectangle = _
> '
Rectangle.Round(bmp.GetBounds(GraphicsUnit.Pixel))
>
> 'g.DrawImage(pb.Image, rect, 0, 0, pb.Width,
pb.Height, _
> ' GraphicsUnit.Pixel, image_attr)
>
> ''pb.Image= bm
> ''gr.Dispose()
> ''bm_src.Dispose()
> ''image_attr.Dispose()
>
> If lFile.EndsWith(".emf") Then
> fmt = Imaging.ImageFormat.Emf
> ElseIf lFile.EndsWith(".exif") Then
> fmt = Imaging.ImageFormat.Exif
> ElseIf lFile.EndsWith(".gif") Then
> fmt = Imaging.ImageFormat.Gif
> ElseIf lFile.EndsWith(".jpg") OrElse
lFile.EndsWith(".jpeg")
> Then
> fmt = Imaging.ImageFormat.Jpeg
> ElseIf lFile.EndsWith(".png") Then
> fmt = Imaging.ImageFormat.Png
> ElseIf lFile.EndsWith(".tiff") OrElse
lFile.EndsWith(".tif")
> Then
> fmt = Imaging.ImageFormat.Tiff
> ElseIf lFile.EndsWith(".wmf") Then
> fmt = Imaging.ImageFormat.Wmf
> Else
> fmt = Imaging.ImageFormat.Bmp
> End If
> bmp.Save(sFile, fmt)
>
> g.Dispose()
> bmp.Dispose()
> pe.Dispose()
>
> End Sub
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "DotNetDevelopment, VB.NET, C# .NET,
ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting"
group.
To post to this group, send email to DotNetDevelopment googlegroups.com
To unsubscribe from this group, send email to
DotNetDevelopment-unsubscribe googlegroups.com
For more options, visit this group at
http:
//cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---
|