|
There are number of useful articles present on the Codeproject site itself.
Just search for articles.
|
|
|
|
|
I am using barcode image of type bitmap and have assiged to picturebox. The original image size is larger than picturebox size, so i have used the property "Sizemode=stretch" because i want the image to be displayed in picturebox size.
after doing so and trying to print the form, the quality of image present in picturebox comes out very poor,the lines of barcode look like they have got mixed with each other,image is distorted .
if i increase the size of picturebox, print is very clear, but i need to print image in small size.
may i know some solution?
modified on Saturday, November 8, 2008 9:27 AM
|
|
|
|
|
What's the component you're using to generate the barcode image?? Does this component let you specifiy the size of the image you want?? If not, I suggest looking for another component.
|
|
|
|
|
Probably that`s because the bitmap you`re loading has a different aspect ratio from the picture box ur fitting it into. Stretch means that the image will fill the container, so it your picture box has a size like Width:200, Height:150 and the barcode has let`s say Width: 100, Height: 120 it will appear disproportioned in the picture box.
One way to get around this would be this:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim _hW As Single = Me.PictureBox1.Image.Width
Dim _hH As Single = Me.PictureBox1.Image.Height
Dim ratio As Single = IIf(_hW >= _hH, _hW / _hH, _hH / _hW)
'resize image according to which is the highest ... Width or Height
If (_hW > _hH) Then
Me.PictureBox1.Image = ResizeImg(Me.PictureBox1.Image, New Size(Me.PictureBox1.Width, Me.PictureBox1.Width / ratio))
Else
Me.PictureBox1.Image = ResizeImg(Me.PictureBox1.Image, New Size(Me.PictureBox1.Height / ratio, Me.PictureBox1.Height))
End If
End Sub
Public Function ResizeImg(ByVal img As Image, ByVal size As Size) As Image
Dim bm As Bitmap = New Bitmap(img, Convert.ToUInt32(size.Width), Convert.ToUInt32(size.Height))
Dim myNewImage As Graphics = Graphics.FromImage(bm)
myNewImage.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
Return bm
End Function
The above code assumes that the barcode image is loaded in the picturebox at runtime. You can modify the code to fit ur exact needs moving the Form1_Load code to the place in code where u need it.
If the program that generates your barcodes allows it, try increasing the HEIGHT of the bars to fit into the picture boxes aspect ratio.
|
|
|
|
|
I tried the code you have given but the image is still not clear.
Can this happen beacause of Virus? My system is badly infected.
modified on Sunday, November 9, 2008 11:41 PM
|
|
|
|
|
Hi Friends I am Converting my VB6 project into VB.net but I an able to convert these lines of code into VB.net Some body plz help me...
UnRGB picImage.Point(r, c), clrr, clrg, clrb
where r c can be any point related to x,y
Private Sub UnRGB(ByVal color As OLE_COLOR, ByRef r As Byte, ByRef g As Byte, ByRef b As Byte)
r = color And &HFF&
g = (color And &HFF00&) \ &H100&
b = (color And &HFF0000) \ &H10000
End Sub
WHERE THE PROBLEM IS THIS THAT OLE_COLOR IS NOT VALID INTO VB.NET.......
Please guide me if you can
|
|
|
|
|
sarfarazaliqureshi wrote: Private Sub UnRGB(ByVal color As OLE_COLOR, ByRef r As Byte, ByRef g As Byte, ByRef b As Byte)
So what does the code look like in the VB6 code that defined OLE_COLOR??
|
|
|
|
|
Actually this code is from a program Steganography.......
Private Sub EncodeByte(ByVal Value As Byte, ByVal used_positions As Collection, ByVal wid As Integer, ByVal hgt As Integer, ByVal show_pixels As Boolean)
Dim i As Integer
Dim byte_mask As Integer
Dim r As Integer
Dim c As Integer
Dim pixel As Integer
Dim clrr As Byte
Dim clrg As Byte
Dim clrb As Byte
Dim color_mask As Integer
byte_mask = 1
For i = 1 To 8
' Pick a random pixel and RGB component.
PickPosition used_positions, wid, hgt, r, c, pixel
' Get the pixel's color components.
UnRGB picImage.Point(r, c), clrr, clrg, clrb
If show_pixels Then
clrr = 255
clrg = clrg And &H1
clrb = clrb And &H1
End If
' Get the value we must store.
If Value And byte_mask Then
color_mask = 1
Else
color_mask = 0
End If
' Update the color.
Select Case pixel
Case 0
clrr = (clrr And &HFE) Or color_mask
Case 1
clrg = (clrg And &HFE) Or color_mask
Case 2
clrb = (clrb And &HFE) Or color_mask
End Select
' Set the pixel's color.
picImage.PSet (r, c), RGB(clrr, clrg, clrb)
byte_mask = byte_mask * 2
Next i
End Sub
Private Sub PickPosition(ByVal used_positions As Collection, ByVal wid As Integer, ByVal hgt As Integer, ByRef r As Integer, ByRef c As Integer, ByRef pixel As Integer)
Dim position_code As String
On Error Resume Next
Do
' Pick a position.
r = Int(Rnd * wid)
c = Int(Rnd * hgt)
pixel = Int(Rnd * 3)
' See if the position is unused.
position_code = "(" & r & "," & c & "," & pixel & ")"
used_positions.Add position_code, position_code
If Err.Number = 0 Then Exit Do
Err.Clear
Loop
End Sub
Private Sub UnRGB(ByVal color As OLE_COLOR, ByRef r As Byte, ByRef g As Byte, ByRef b As Byte)
r = color And &HFF&
g = (color And &HFF00&) \ &H100&
b = (color And &HFF0000) \ &H10000
End Sub
|
|
|
|
|
This is all and wel and good, but you didn't answer the question. Where is the VB6 code that defines OLE_COLOR???
|
|
|
|
|
Since your code looks like ...
UnRGB picImage.Point(r, c), clrr, clrg, clrb
where r c can be any point related to x,y
Private Sub UnRGB(ByVal color As OLE_COLOR, ByRef r As Byte, ByRef g As Byte, ByRef b As Byte)
Edited: taking a 2nd look it should be like this:
dim bm as Bitmap = new Bitmap("your picimage");
dim cr as Color = bm.GetPixel(x,y);
UnRGB (cr, clrr, clrg, clrb)
Private Sub UnRGB(byval cr as Color ...
OLE_COLOR is nothing more than a INT32 value replace in .NET by System.Drawing.Color
You can always use System.Drawing.ColorTranslator.FromOle to convert OLE_COLOR to a .NET Color Object.
Hope it helps.
modified on Saturday, November 8, 2008 5:23 PM
|
|
|
|
|
Thanks Friend Your Reply Really Helped Me thanks Alot.....
|
|
|
|
|
Actually this code is from a program Steganography.......
and I am unable to Write UnRGB procedure in Vb.net b/c if I convert OLE_COLOR into SYSTEM.DRAWING.COLOR then Error Comes that: And operation can not be performed...... any body can help me to write this procedure in Vb.net
Private Sub EncodeByte(ByVal Value As Byte, ByVal used_positions As Collection, ByVal wid As Integer, ByVal hgt As Integer, ByVal show_pixels As Boolean)
Dim i As Integer
Dim byte_mask As Integer
Dim r As Integer
Dim c As Integer
Dim pixel As Integer
Dim clrr As Byte
Dim clrg As Byte
Dim clrb As Byte
Dim color_mask As Integer
byte_mask = 1
For i = 1 To 8
' Pick a random pixel and RGB component.
PickPosition used_positions, wid, hgt, r, c, pixel
' Get the pixel's color components.
UnRGB picImage.Point(r, c), clrr, clrg, clrb
If show_pixels Then
clrr = 255
clrg = clrg And &H1
clrb = clrb And &H1
End If
' Get the value we must store.
If Value And byte_mask Then
color_mask = 1
Else
color_mask = 0
End If
' Update the color.
Select Case pixel
Case 0
clrr = (clrr And &HFE) Or color_mask
Case 1
clrg = (clrg And &HFE) Or color_mask
Case 2
clrb = (clrb And &HFE) Or color_mask
End Select
' Set the pixel's color.
picImage.PSet (r, c), RGB(clrr, clrg, clrb)
byte_mask = byte_mask * 2
Next i
End Sub
Private Sub PickPosition(ByVal used_positions As Collection, ByVal wid As Integer, ByVal hgt As Integer, ByRef r As Integer, ByRef c As Integer, ByRef pixel As Integer)
Dim position_code As String
On Error Resume Next
Do
' Pick a position.
r = Int(Rnd * wid)
c = Int(Rnd * hgt)
pixel = Int(Rnd * 3)
' See if the position is unused.
position_code = "(" & r & "," & c & "," & pixel & ")"
used_positions.Add position_code, position_code
If Err.Number = 0 Then Exit Do
Err.Clear
Loop
End Sub
Private Sub UnRGB(ByVal color As OLE_COLOR, ByRef r As Byte, ByRef g As Byte, ByRef b As Byte)
r = color And &HFF&
g = (color And &HFF00&) \ &H100&
b = (color And &HFF0000) \ &H10000
End Sub
|
|
|
|
|
Hi I m cs std. I m trying to do the Draw chat in AxMSChart control using timer control.When I m moving one y1 axes it will work perfectly when i m trying to do 2 line then bug will come. plz some help me...
This is code I m using.
Dim count As Integer = 1
Dim count1 As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
MSChart1.Column = 1
If count < 500 Then
MSChart1.Data = 800
ElseIf count < 1000 Then
MSChart1.Data = 900
ElseIf count < 1500 Then
MSChart1.Data = 1000
Else
MSChart1.Data = 1100
End If
count = count + 1
MSChart1.Column = 2
If count1 < 500 Then
MSChart1.Data = 1100
ElseIf count1 < 1000 Then
MSChart1.Data = 1000
ElseIf count1 < 1500 Then
MSChart1.Data = 900
Else
MSChart1.Data = 800
End If
count1 = count1 + 5
End Sub
Timer interval is 1000.
any ans send to this E-mail ID <osrnananda@rediffmail.com>
|
|
|
|
|
osrnananda wrote: When I m moving one y1 axes it will work perfectly when i m trying to do 2 line then bug will come
And that bug would be .....???
|
|
|
|
|
I m using Line Chart. When I run code using y1 axes it work correctly but when i try to run both it shows like bar or similarly like bar chart. So plz give me a solution Thanx's
|
|
|
|
|
How do i remove this thing!
I created my crystal report via the wizard.
|
|
|
|
|
|
Thank you! That did it!
Will it also work if i transfer my application in another PC?
|
|
|
|
|
You're welcome
Basically it will work fine. However, it slightly depends on what kind of datasource you have.
If you're connecting to a database server, it will typically works fine as is, but if your datasource is for example a xml file then you have to take care that the directory is correct for database logon in another computer when pointing the file.
If you encounter problems later, open a new thread and we'll try to help.
Mika
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
thank you! it worked.
|
|
|
|
|
You're welcome
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
I need help understanding this procedure.
The project I am working on requires me to printout a form and email it to another department in myh company. The printout is exactly the way I want it, but I am not clear on how to save the PrintDocument to an image. The following link has an example of exactly what I am trying to accomplish, but don't understand how to use "MyObj" to do both.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2664510&SiteID=1[^]
Any help would be appreciated
|
|
|
|
|
What's "MyObj"?? I don't see that anywhere in that code you linked to. I thought the code was pretty self explanitory. What don't you understand about it??
|
|
|
|
|
I found that the code I tried to use earlier for my project didn't work for me (link). So, I found code that did what I needed, and that I could understand. This is the code that I used.
<pre>
Option Strict Off
Public Class Form1
Dim pdoc As New Printing.PrintDocument()
Friend WithEvents ppc As New Printing.PreviewPrintController()
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
pdoc.PrintController = ppc
AddHandler pdoc.PrintPage, AddressOf pdoc_PrintPage
AddHandler pdoc.EndPrint, AddressOf xxx
' This shows nothing on the screen. It ends
' up calling the 'xxx' sub which saves the
' printpage images to files
pdoc.Print()
' This will show a regular print preview
pdoc.PrintController = New Printing.StandardPrintController
Dim ppd As New PrintPreviewDialog
ppd.Document = pdoc
ppd.ShowDialog()
End Sub
Private Sub pdoc_PrintPage(ByVal sender As Object, _
ByVal e As Printing.PrintPageEventArgs)
Static z As Integer = 0
If z = 0 Then
e.Graphics.DrawString("Page pg1", New Font("Arial", 48), _
Brushes.Black, New PointF(100, 100))
z += 1
e.HasMorePages = True
ElseIf z = 1 Then
e.Graphics.DrawString("Page pg2", New Font("Arial", 48), _
Brushes.Black, New PointF(100, 100))
z += 1
e.HasMorePages = True
Else
e.Graphics.DrawString("Page pg3", New Font("Arial", 48), _
Brushes.Black, New PointF(100, 100))
e.HasMorePages = False
z = 0
End If
End Sub
Private Sub xxx(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintEventArgs)
Dim ppi() As Printing.PreviewPageInfo = ppc.GetPreviewPageInfo()
For x As Integer = 0 To ppi.Length - 1
ppi(x).Image.Save("c:\look" & x.ToString & ".jpg")
Next
End Sub
End Class
</pre>
Hope this comes in handy for someone else
|
|
|
|
|
I'm writing an application to receive data from a hardware data logger and display it. The concept involves getting the data from a serial port, displaying it in a grid control, graphing it, then saving it in an ASCII delimited format.
So far, I receive the data and I load it directly into a DataGridView. As many of you know, this is extremely slow, especially for tens of thousands of data entries. I've read in a few places that it is more appropriate / efficient / expedient to use a DataGridView by binding it to a source of data. Much of the info I've found on the web relating to this concept deals with databases rather than a port based data stream.
I think my first design flaw was considering the DataGridView the actual data container. Much of this comes from using MSflexgrid in the past.
My questions are...
- Conceptually or architecturally how would you approach this problem?
- In what type of "container" should I receive the data into memory such that it will allow for easy manipulation (grid display, graphing, saving)?
Can anyone point me in the right direction? Thanks in advance.
|
|
|
|
|