VB.NET Tool for Image Printing - Quality Ajustments - vb.net

I'm developing a tool for easy picture printing with a canon selpy cp800. The Image is printed with the following methods:
Private Sub BtnPrintClick(sender As Object, e As System.EventArgs) Handles ptnPrint.Click
If PrintDialog1.ShowDialog() = DialogResult.OK Then
pdPrintImage.Print()
End If
End Sub
Private Sub PdPrintImagePrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles pdPrintImage.PrintPage
e.Graphics.DrawImage(_dPictures(_sPictures(_iActiveImage)).Picture, e.Graphics.VisibleClipBounds)
End Sub
_dPictures(_sPictures(_iActiveImage)).Picture --> object of the type image
I didn't do anything with this image. It's only loaded with the Image.FromFile() method.
Within the following image you can see my problem. This is a scan of the image printed with this method (top) and a scan of the same image printed with the windows picture viewer. You see, the first image you see the tonal errors in the background and the shadows.
Has anyone an idea to fix this?

If it isn't a bit-depth issue as Boo mentioned, it might help to set one or both of these
e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
before doing the .DrawImage.

the best quality I achieved as follows:
1) I put a picture into pdf using components iTextsharp.
2) print the pdf

Related

XtraReport show image in picturebox one time only

I've created an xtrareport that contains picturebox and i set the image through xrPictureBox1.ImageUrl in XrPictureBox1_BeforePrint event.
when i open the report for the first time, the images showing properly, but when reload report and reopen it again the images not showing.
I'm using version 17.2.
please help!
Regards.
Private Sub XrPictureBox1_BeforePrint(sender As Object, e As PrintEventArgs) Handles XrPictureBox1.BeforePrint
XrPictureBox1.ImageUrl = HttpContext.Current.Server.MapPath("~/TaskFiles/" & XrTableCell9.Text)
End Sub

Dynamically changing image in picture box not working

I've been trying to figure this out off-and-on for weeks.
In my VB 2010 Forms application, I have a number of picture boxes which are populated with images from other picture boxes using the drag-and-drop method. That's no problem, it works fine. The picture boxes are all in a groupbox container.
The problem is trying to swap images between two picture boxes on a drag-and drop operation. In other words pBox1 has image.x and pBox2 has image.y. Drag the image from pBox2 to pBox1, and drop it; pBox1 will then have image.y from pBox2 and pBox2 will have image.x from pBox1.
With this example, here's the code I have so far:
Private Sub pBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pBox1.MouseDown
strImageSource = "pBox2" 'strImageSource is a global string variable
[other stuff]
end sub
^ This saves the name of the source picture box to a global string.
Private Sub pBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pBox1.DragDrop
For Each Control as PictureBox in GroupBox1.Controls.OfType(of PictureBox)()
if Control.Name = strImageSource then
Control.Image = pBox1.Image
end if
next
dim imgTarget as Image = CType((e.Data.GetData(DataFormats.Bitmap)), Bitmap)
pBox1.image = imgTarget
End Sub
^ This searches for the picture box as named by the strImageSource ("pBox2") and copies the contents of pBox1 into it, and then drops the image that was in pBox2 into pBox1.
I hope this makes sense.
This correctly places the image from pBox2 into pBox1, but it does not switch the image from pBox1 into pBox2. pBox2 is just blank. However, debugging shows that the image in pBox2 is not nothing; it does contain a bitmap. It's just not visible.
Now, just as a test, I added a line to the For Each section that would change the background color of the picture box:
For Each Control as PictureBox in GroupBox1.Controls.OfType(of PictureBox)()
if Control.Name = strImageSource then
Control.Image = pBox1.Image
Control.BackColor = color.red
end if
next
And the back color does change. This tells me that the For Each section is working -- it's finding the control and changing the back color. It's just not showing the image.
Is there something I am overlooking?
Thanks!
Instead of using strImageSource, use a global variable defined as a Picturebox
Private tmpPictureBox As PictureBox
Then store that picturebox reference so you can set its image on DragDrop
Private Sub pBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pBox1.MouseDown
'store the picturebox reference
tmpPictureBox = sender
[other stuff]
end sub
Private Sub pBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pBox1.DragDrop
'set the first image to the second
tmpPictureBox.Image = sender.image
'set the second image to the first
pBox1.image = CType((e.Data.GetData(DataFormats.Bitmap)), Bitmap)
End Sub
You should call Control.Refresh() on the PictureBox controls in order to update the images.
OK, this was stupid.
I was doing everything right with one really boneheaded exception. In another part of the code, inexplicably, I was clearing the picture boxes of content after the image was replaced. It may have been a remnant of something I was trying to do unrelated to this problem, and I just never corrected it.
My apologies for that, and thanks for all the responses.

Loading images from a folder [VB.NET]

I'm currently experiencing a problem with my program. I want to create a photo gallery for my girlfriend which she can install on her computer. I want to import images from a folder on Form load and display them in a PictureBox.
When I load the Form I get a big red 'X' that fills the box. Looks like the drawing.bitmap ErrorImage. What could be the problem? Any help is greatly appreciated. Thank you.
Private Sub Pigge_Gallary_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim directory As New IO.DirectoryInfo("C:\Pics\Bears")
If directory.Exists Then
Dim jpgFiles() As IO.FileInfo = directory.GetFiles("*.jpg")
For Each jpgFile As IO.FileInfo In jpgFiles
If jpgFile.Exists Then
Dim image = Drawing.Image.FromFile(jpgFile.FullName)
Using image
PicPig.Image = image
End Using
End If
Next
End If
End Sub
Once you exit the Using block, you're losing the image reference.
Try changing
PicPig.Image = image
to
PicPig.Image = image.clone
or just set it to the image from the file:
PicPig.Image = Drawing.Image.FromFile(jpgFile.FullName)
Also, because you're doing it in a For loop, it's just going to replace the picturebox image as it loops. When it finishes the loop, the picturebox will only be displaying the last image.

Dynamically resize font to fill up RichTextbox

How do i dynamically resize the text in a RichTextbox so that it fills up the entire rich textbox?
any help is much appreciated. thank you.
This MSDN article almost answers your question. http://msdn.microsoft.com/en-us/library/bb986765.aspx.
You may download the attached sample there.
I think you might have to get creative with the 'Font' constructor. For example, on a click event then construct a new Font using some relationship with your application (or textbox size) with the desired font size.
Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
Dim yourfontsize As Integer
'machinery to create desired font size
If blah then
yourfontsize = X()
Else
yourfontsize = Y()
End If
yourtextbox.SelectionFont = New Font("Tahoma", yourfontsize, FontStyle.Bold)
End Sub
Where X() and Y() are functions to return your target font sizes based on whatever else may
be going on within your application.
Reference: http://msdn.microsoft.com/en-us/library/yh8963yx.aspx
Hope that helps!
-sf

How to rotate a PictureBox on a windows form using vb.net

I need to rotate a picture box 180 degrees when a condition in my if statement is met. Is this possible?
I'll assume that you want to rotate the image inside, because rotating the box itself doesn't make much sense (and is impossible anyway).
Try this:
myPictureBox.Image.RotateFlip(RotateFlipType.Rotate180FlipNone);
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipNone)
PictureBox1.Refresh()
When you try to rotate your image with:
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipNone)
nothing will happen until you close the form and open it again (not the project, just the form). If you want to rotate at once then you should use PictureBox1.Refresh().
The System.Drawing.Image.RotateFlip() method allows you to rotate the actual image displayed in the picturebox. See this page
Dim bitmap1 As Bitmap
Private Sub InitializeBitmap()
Try
bitmap1 = CType(Bitmap.FromFile("C:\Documents and Settings\All Users\" _
& "Documents\My Music\music.bmp"), Bitmap)
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox1.Image = bitmap1
Catch ex As System.IO.FileNotFoundException
MessageBox.Show("There was an error. Check the path to the bitmap.")
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If bitmap1 IsNot Nothing Then
bitmap1.RotateFlip(RotateFlipType.Rotate180FlipY)
PictureBox1.Image = bitmap1
End If
End Sub
You grasp the concepts for C++ as given in
http://www.codeproject.com/KB/cpp/rimage.aspx
and may use for VB.net as given in
http://www.eggheadcafe.com/community/aspnet/14/10053817/rotating-picturebox-contr.aspx