Hi group I already posted this problem yesterday, and I've found a
"solution", but I don't like it, in my opnion there has to be an easier way
to do this, but I can't find, I hope some one can help me with this. Just
copy paste the code in an empty form and press the draw button, then press
the resize button to see what it does, but I just don't like the way I do
it, and I can't seem to find an easier way
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.PictureBox2 = New System.Windows.Forms.PictureBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(34, 42)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(301, 301)
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'PictureBox2
'
Me.PictureBox2.Location = New System.Drawing.Point(418, 42)
Me.PictureBox2.Name = "PictureBox2"
Me.PictureBox2.Size = New System.Drawing.Size(140, 140)
Me.PictureBox2.TabIndex = 1
Me.PictureBox2.TabStop = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(94, 10)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 2
Me.Button1.Text = "Draw"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(198, 10)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(72, 22)
Me.Button2.TabIndex = 3
Me.Button2.Text = "Resize"
Me.Button2.Visible = False
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(740, 419)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2,
Me.Button1, Me.PictureBox2, Me.PictureBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim g As Graphics
Dim b As New Bitmap(301, 301)
g = Graphics.FromImage(b)
g.Clear(Color.White)
g.DrawLine(New Pen(Color.Black), 0, 0, 300, 0)
g.DrawLine(New Pen(Color.Black), 0, 300, 0, 0)
g.DrawLine(New Pen(Color.Black), 300, 0, 300, 300)
g.DrawLine(New Pen(Color.Black), 300, 300, 0, 300)
PictureBox1.Image = b
g.Dispose()
Button2.Visible = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Try
Dim g2 As Graphics
Dim scale As Double
scale = 301 / 128
Dim bNew As New Bitmap(CInt(301 / scale) + 1, CInt(301 / scale)
+ 1)
g2 = Graphics.FromImage(bNew)
g2.Clear(Color.White)
g2.PixelOffsetMode =
Drawing.Drawing2D.PixelOffsetMode.HighQuality
g2.DrawImage(PictureBox1.Image, New Rectangle(0, 0, CInt(301 /
scale), CInt(301 / scale)), 0, 0, PictureBox1.Image.Width,
PictureBox1.Image.Height, GraphicsUnit.Pixel)
black(bNew)
PictureBox2.Image = bNew
g2.Dispose()
Catch ex As Exception
ex.ToString()
End Try
End Sub
Private Sub black(ByVal pBitmap As Bitmap)
Dim row, col As Integer
For row = 0 To 128
For col = 0 To 128
If pBitmap.GetPixel(col, row).Name <> "ffffffff" Then
pBitmap.SetPixel(col, row, Color.Black)
End If
Next
Next
End Sub
End Class 11 1121
Peter,
Depends on what you want to do, do you really want to make a smaller picture
or do you want to show the picture in a smaller picturebox.
I use a kind of this methode when i want to cut of parts of the picture.
When it would be for showing in another way I would use the sizemode of the
picturebox.
Cor
I realy want to resize the picture and then save it, because I need the
picture at 128*128
grtz Peter
"Cor Ligthert" <no************@planet.nl> wrote in message
news:OE*************@TK2MSFTNGP09.phx.gbl... Peter,
Depends on what you want to do, do you really want to make a smaller
picture or do you want to show the picture in a smaller picturebox.
I use a kind of this methode when i want to cut of parts of the picture.
When it would be for showing in another way I would use the sizemode of
the picturebox.
Cor
Peter,
And not a thumbnail, because therefore is a special method?
Cor
Hi Cor, no I don't need an thumbnail. It's a dynamic drawing program I've
made on which the user can draw and resize a real window by using
parameters, the original drawing is done on a maximum 400*400 bitmap, but
after the drawing is done I need to save it as maximum 128*128 bitmap, for
example if they draw a window which is 1000mm large and 500mm high the
orignal bitmap will be 400*200 but then I need to convert it to a 128*64
bitmap and I thought it would work with the graphics.drawimage and the
correct dimensions but if I use this method the right and bottom line of the
picture get cut off, this happens if you in the code I posted comment out
the line
g2.pixeloffsetmode = drawing2d.pixeloffsetMode.highquality
If I use the
g2.pixeloffsetmode = drawing2d.pixeloffsetMode.highquality
line, it works ok but the the color isn't black anymore, that's why I create
the black(bitmap) method in the code
Grtz Peter & thnx for your help
"Cor Ligthert" <no************@planet.nl> wrote in message
news:O8**************@tk2msftngp13.phx.gbl... Peter,
And not a thumbnail, because therefore is a special method?
Cor
Peter,
Thanks because with this post you resolve a problem I once had and now know
that there is an answer.
Cor
I'm glad I could help you for once, because normaly it's you helping the
people here, but have you got an idea how I can solve my little problem?
Because I realy would like the image to stay black and white and preferably
not by using my method to go over the entire bitmap pixel by pixel.
thnx Peter
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uH*************@TK2MSFTNGP11.phx.gbl... Peter,
Thanks because with this post you resolve a problem I once had and now
know that there is an answer.
Cor
"Peter Proost" <pp*****@nospam.hotmail.com> wrote Hi group I already posted this problem yesterday, and I've found a "solution", but I don't like it, in my opnion there has to be an easier way to do this, but I can't find, I hope some one can help me with this. Just copy paste the code in an empty form and press the draw button, then press the resize button to see what it does, but I just don't like the way I do it, and I can't seem to find an easier way
You haven't really described the problem. However the small image I
saw had a white border at the left an right. That means you must have
made the image too big:
Dim bNew As New Bitmap(CInt(301 / scale) + 1, CInt(301 / scale) + 1)
S/B
Dim bNew As New Bitmap(CInt(301 / scale), CInt(301 / scale))
Then comment out your black line:
black(bNew)
S/B
' black(bNew)
Is that better?
LFS
Hi larry thnx for your response I know about the white border, but when I do
it like that the image isn't black anymore, thats why I wrote the black
method,
grtz Peter
"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:#S**************@TK2MSFTNGP14.phx.gbl... "Peter Proost" <pp*****@nospam.hotmail.com> wrote
Hi group I already posted this problem yesterday, and I've found a "solution", but I don't like it, in my opnion there has to be an easier
way to do this, but I can't find, I hope some one can help me with this.
Just copy paste the code in an empty form and press the draw button, then
press the resize button to see what it does, but I just don't like the way I
do it, and I can't seem to find an easier way You haven't really described the problem. However the small image I saw had a white border at the left an right. That means you must have made the image too big:
Dim bNew As New Bitmap(CInt(301 / scale) + 1, CInt(301 /
scale) + 1) S/B
Dim bNew As New Bitmap(CInt(301 / scale), CInt(301 / scale))
Then comment out your black line:
black(bNew)
S/B
' black(bNew)
Is that better? LFS
"Peter Proost" <pp*****@nospam.hotmail.com> wrote I'm glad I could help you for once, because normaly it's you helping the people here, but have you got an idea how I can solve my little problem? Because I realy would like the image to stay black and white and preferably not by using my method to go over the entire bitmap pixel by pixel.
thnx Peter
I think the border would be the least of your worries. Add a couple ellipeses
to the drawing and then try different interpolation modes. Its the drawing you
want to look nice, is it not?
Draw these:
g.DrawRectangle(Pens.Black, 0, 0, 300, 300)
g.DrawEllipse(Pens.Blue, 30, 30, 50, 90)
g.DrawEllipse(Pens.Green, 30, 100, 150, 50)
And try this combination:
g2.Clear(Color.Black)
g2.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBilinear
g2.DrawImage(PictureBox1.Image, New Rectangle(0, 0, CInt(301 / scale), CInt(301 / scale)), 0, 0,
PictureBox1.Image.Width, PictureBox1.Image.Height, GraphicsUnit.Pixel)
Don't call your Black routine. See if that will work OK....
LFS
Hello Larry that works but also makes the black rectangle gray, and I want
it to stay black, if I don't use an interpolationMode it stays black but the
right and bottom border of the square are cut off, and the border is very
important because my program draws the picture of a real window and a window
without a border,frame wouldn't look nice ;-)
thnx for your time and help
PS: first I got an all black square but that was because
g2.clear(color.black) :-)
"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:Or**************@TK2MSFTNGP15.phx.gbl... "Peter Proost" <pp*****@nospam.hotmail.com> wrote I'm glad I could help you for once, because normaly it's you helping the people here, but have you got an idea how I can solve my little problem? Because I realy would like the image to stay black and white and
preferably not by using my method to go over the entire bitmap pixel by pixel.
thnx Peter I think the border would be the least of your worries. Add a couple
ellipeses to the drawing and then try different interpolation modes. Its the
drawing you want to look nice, is it not?
Draw these:
g.DrawRectangle(Pens.Black, 0, 0, 300, 300) g.DrawEllipse(Pens.Blue, 30, 30, 50, 90) g.DrawEllipse(Pens.Green, 30, 100, 150, 50)
And try this combination:
g2.Clear(Color.Black) g2.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBilinear g2.DrawImage(PictureBox1.Image, New Rectangle(0, 0, CInt(301 /
scale), CInt(301 / scale)), 0, 0, PictureBox1.Image.Width, PictureBox1.Image.Height, GraphicsUnit.Pixel)
Don't call your Black routine. See if that will work OK....
LFS
Hi just to let you know that I've found a solution that works for me, before
I resize the picture to it's smaller format, I first resize to a bigger
bitmap so that the my original pictures border isn't the border anymore, I
start drawing on the bigger bitmap at point (10,10) and thus the black lines
don't get cut off when I resize the image to a smaller size and the picture
stays black&white because I don't have to use an interpolationMode
Thnx Larry&Cor for your time&help
greetz Peter
"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:e7**************@tk2msftngp13.phx.gbl... Hello Larry that works but also makes the black rectangle gray, and I want it to stay black, if I don't use an interpolationMode it stays black but
the right and bottom border of the square are cut off, and the border is very important because my program draws the picture of a real window and a
window without a border,frame wouldn't look nice ;-)
thnx for your time and help
PS: first I got an all black square but that was because g2.clear(color.black) :-)
"Larry Serflaten" <se*******@usinternet.com> wrote in message news:Or**************@TK2MSFTNGP15.phx.gbl... "Peter Proost" <pp*****@nospam.hotmail.com> wrote I'm glad I could help you for once, because normaly it's you helping
the people here, but have you got an idea how I can solve my little
problem? Because I realy would like the image to stay black and white and preferably not by using my method to go over the entire bitmap pixel by pixel.
thnx Peter I think the border would be the least of your worries. Add a couple ellipeses to the drawing and then try different interpolation modes. Its the drawing you want to look nice, is it not?
Draw these:
g.DrawRectangle(Pens.Black, 0, 0, 300, 300) g.DrawEllipse(Pens.Blue, 30, 30, 50, 90) g.DrawEllipse(Pens.Green, 30, 100, 150, 50)
And try this combination:
g2.Clear(Color.Black) g2.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBilinear g2.DrawImage(PictureBox1.Image, New Rectangle(0, 0, CInt(301
/ scale), CInt(301 / scale)), 0, 0, PictureBox1.Image.Width, PictureBox1.Image.Height, GraphicsUnit.Pixel)
Don't call your Black routine. See if that will work OK....
LFS
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: SeeBelow |
last post by:
I see the value of a class when two or more instances will be created,
but Python programmers regularly use a class when there will only be one
instance.
What is the benefit of this? It has a...
|
by: Mario T. Lanza |
last post by:
Greetings,
I have been developing websites in CSS for a couple years; I claim to
be no expert, but certain things could definitely be easier.
Consider the box model and it's different...
|
by: Willem |
last post by:
Looking for some opinions on alternatives to programming with Access.
I find that quite often I need to loop through my recordsets (first to
last) performing calculations and was wondering if...
|
by: Peter |
last post by:
Hello,
Thanks for reviewing my question. I would like to know if there is an easier way to regenerate your dataset in VS.NET when your database schema changes. I am frequently add or remove...
|
by: Mitchell S. Honnert |
last post by:
In some recent posts, I've seen people who seem to be waxing nostalgic with
respect to the "ease of use" of Visual Basic 6. I can't quite put my finger
on it, but they seem to be implying that VB6...
|
by: Greg |
last post by:
Except for legacy or non-.NET applications, is there any reason to use VC++
anymore? It seems that for .NET applications, there would be no reason to
choose C++ over C# since C# is faster to...
|
by: walter.preuninger |
last post by:
Is there an easier way to code the cmp procedure without going thru all
the pointer manipulations?
#include <stdlib.h>
#include <string.h>
int cmp(const void *i, const void *j)
{
void *p1,...
|
by: Kamilche |
last post by:
I have been programming in Python for years, and I'm STILL learning new
features about the language.
I'm looking for the best way to handle events with my own UI developed
in PyGame, and I've...
|
by: Ares6881 |
last post by:
Hi, I was wondering if there's an easier way to get a week range than what I'm currently using. Right now I use something along these lines, where drequest is the date
Format(,"yyyy") &...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |