Click here to Skip to main content
15,896,278 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
Dave Kreskowiak15-Jan-07 5:36
mveDave Kreskowiak15-Jan-07 5:36 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg16-Jan-07 3:24
vbbeg16-Jan-07 3:24 
QuestionAnyone know any good resources on developing right-click/context menus for form controls??? Pin
Joey Picerno11-Jan-07 5:41
Joey Picerno11-Jan-07 5:41 
AnswerRe: Anyone know any good resources on developing right-click/context menus for form controls??? Pin
Kschuler11-Jan-07 9:07
Kschuler11-Jan-07 9:07 
QuestionAnother question about Graphics.DrawString Pin
Savas Cilve11-Jan-07 4:10
Savas Cilve11-Jan-07 4:10 
AnswerRe: Another question about Graphics.DrawString Pin
Dave Kreskowiak11-Jan-07 4:15
mveDave Kreskowiak11-Jan-07 4:15 
GeneralRe: Another question about Graphics.DrawString Pin
Savas Cilve11-Jan-07 4:23
Savas Cilve11-Jan-07 4:23 
GeneralRe: Another question about Graphics.DrawString Pin
Dave Kreskowiak11-Jan-07 5:37
mveDave Kreskowiak11-Jan-07 5:37 
Again, nowhere in your code do you call Dispose() on the Graphics object you're creating. You MUST ALWAYS call .Dispose() on a Graphics object when you're done using it, otherwise you get odd behavior, kind of like changes not being saved, when manipulating images and your app is suddenly leaking GDI Handles and will eventually crash the system! BTW, you also have to .Dispose() Font objects when you're done with them too.

Since you're only using the Graphics object when a property item contains a certain value, I suggest not creating any Graphics or Font objects unless you need them:
Imports System.Drawing.Imaging
.
.
.
For Each img As Image In _images
    Dim changed As Boolean = False
    Dim pi() As Drawing.Imaging.PropertyItem = img.PropertyItems
 
    For Each pItem As Drawing.Imaging.PropertyItem In pi
        If pItem.Id = 36867 Then
            Dim bytes() As Byte = pItem.Value
            Dim f As New Font(FontFamily.GenericSerif, 35.0F, FontStyle.Regular, GraphicsUnit.Point)
            Dim graph As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(img)
            Dim enc As New System.Text.UTF8Encoding
 
            graph.DrawString(enc.GetString(bytes), f, Brushes.Yellow, CSng(img.Width) - 400.0F, CSng(img.Height) - 50.0F)
            graph.Dispose()
            f.Dipose()
 
            ' Create a JPEG Encoder and set it's Compression quality
            Dim jpegCodec As ImageCodecInfo = GetEncoderInfo("image/jpeg")
            Dim encoderParams As New EncoderParameters(1)
            encoderParams.Param[0] = New EncoderParameter(Encoder.Quality, 100)
 
            ' Save the image using the new encoder
            img.Save(_imagesHash.Item(img).ToString() & ".jpg", jpegCodec, encoderParams)
            Exit For
        End If
    Next
Next
 
.
.
.
 
Public Shared Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
    ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders()
 
    For i As Integer = 0 To codecs.Length
        If codecs[i].MimeType = mimeType Then
            Return codecs[i]
	End If
    Next
    Return Nothing
End Sub

The reason why it's size changes is because you didn't specify the format to use when the image is saved. In your case, the image is saved as PNG format, not JPG. The filename you give doesn't determine the format of the image written. If you want to save an image in JPG format, you have to tell it to do so. If you want to control the compression used on the JPG image, you have to add EncoderParameters to spell out how the JPG should be handled. Those above has been modified to do this.



Dave Kreskowiak
Microsoft MVP - Visual Basic


GeneralRe: Another question about Graphics.DrawString Pin
Savas Cilve11-Jan-07 6:08
Savas Cilve11-Jan-07 6:08 
QuestionInsert File Pin
jds120711-Jan-07 3:56
jds120711-Jan-07 3:56 
QuestionWhat??? Pin
CPallini11-Jan-07 4:06
mveCPallini11-Jan-07 4:06 
AnswerRe: Insert File Pin
Dave Kreskowiak11-Jan-07 4:12
mveDave Kreskowiak11-Jan-07 4:12 
GeneralRe: Insert File Pin
Colin Angus Mackay11-Jan-07 4:51
Colin Angus Mackay11-Jan-07 4:51 
GeneralRe: Insert File Pin
Dave Kreskowiak11-Jan-07 4:56
mveDave Kreskowiak11-Jan-07 4:56 
GeneralRe: Insert File Pin
jds120711-Jan-07 6:01
jds120711-Jan-07 6:01 
GeneralRe: Insert File Pin
Dave Kreskowiak11-Jan-07 6:52
mveDave Kreskowiak11-Jan-07 6:52 
GeneralRe: Insert File Pin
jds120711-Jan-07 7:25
jds120711-Jan-07 7:25 
QuestionWhat does it return? Pin
ashwath197911-Jan-07 3:48
ashwath197911-Jan-07 3:48 
AnswerRe: What does it return? Pin
CPallini11-Jan-07 3:59
mveCPallini11-Jan-07 3:59 
QuestionWhat does it return? Pin
ashwath197911-Jan-07 3:47
ashwath197911-Jan-07 3:47 
QuestionVB.Net Project making Pin
Mayuri Gaikwad11-Jan-07 2:44
Mayuri Gaikwad11-Jan-07 2:44 
AnswerRe: VB.Net Project making Pin
Dave Kreskowiak11-Jan-07 3:11
mveDave Kreskowiak11-Jan-07 3:11 
QuestionI am converting a ActiveX(DSO Framer)control into .Net assembly Pin
indian14311-Jan-07 1:53
indian14311-Jan-07 1:53 
AnswerRe: I am converting a ActiveX(DSO Framer)control into .Net assembly [modified] Pin
Dave Kreskowiak11-Jan-07 3:11
mveDave Kreskowiak11-Jan-07 3:11 
QuestionWhy Startup form may appear behind other programs?? Pin
kindman_nb11-Jan-07 1:48
kindman_nb11-Jan-07 1:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.