Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PictureBox in code

14 views
Skip to first unread message

DaveO

unread,
May 8, 2013, 6:30:13 AM5/8/13
to
Hi

I'm pretty sure I'm missing something obvious here but although I tried a
variety of search terms Google was not much help.

I have a picture in a PictureBox that needs some alteration and then saving,
easy enough using a hidden PictureBox or two but I'd rather not so I
wondered about using a PicutreBox in code that's never shown.

So this is nothing like what I tried but it does show the same problem: when
I alter the image in VPic the original also changes which is exactly what I
don't want to happen.
I think the problem is the Set line, I should probably set VPic as an empty
picture and then copy the image from picTest but I have not been able to
work out how to do that.

Dim VPic As PictureBox
Set VPic.Picture = picTest.Picture
VPic.CurrentX = 60
VPic.CurrentY = 70
VPic.FontName = "Tahoma"
VPic.FontSize = 24
VPic.Print "TEST"

picTest is a visible ordinary PictureBox with a loaded image, AutoRedraw =
True , Scalemode = Pixels

Use of a PictureBox is not essential, any object that holds a picture and
has a hDC would probably suffice as the alterations I perform are any
permutation of Crop, Rescale & Convert to Greyscale, and to make life more
interesting some of this can be done automatically by the Jpeg routine if
saving to Jpeg but if saving to Bmp it all needs to be done in code to
present SavePicture with something it can use. This means that for some
conditions no extra image will be needed and for some others up to 3
intermediate images are required. There's also a preview function which as
it does not use the Jpeg routine does everything in code. ---
Fun-on-a-stick.

Best Regards
DaveO


Deanna Earley

unread,
May 8, 2013, 9:21:57 AM5/8/13
to
On 08/05/2013 11:30, DaveO wrote:
> I have a picture in a PictureBox that needs some alteration and then saving,
> easy enough using a hidden PictureBox or two but I'd rather not so I
> wondered about using a PicutreBox in code that's never shown.

You may want to investigate the VB6 DIBSection implementations that are
floating around the internet.

> So this is nothing like what I tried but it does show the same problem: when
> I alter the image in VPic the original also changes which is exactly what I
> don't want to happen.
> I think the problem is the Set line, I should probably set VPic as an empty
> picture and then copy the image from picTest but I have not been able to
> work out how to do that.
>
> Dim VPic As PictureBox
> Set VPic.Picture = picTest.Picture
> VPic.CurrentX = 60
> VPic.CurrentY = 70
> VPic.FontName = "Tahoma"
> VPic.FontSize = 24
> VPic.Print "TEST"
>
> picTest is a visible ordinary PictureBox with a loaded image, AutoRedraw =
> True , Scalemode = Pixels

Does exactly as expected for me.
The text appears on the VPic picturebox only.
Note that the .Picture property is never changed by the drawing methods.
You need to call .Image to get the drawn results, and so, using native
VB operations, the underlying StdPicture object will never be changed.

Your sample also omits where it gets/creates VPic from.

--
Deanna Earley (dee.e...@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)

DaveO

unread,
May 8, 2013, 10:17:38 AM5/8/13
to
>> Dim VPic As PictureBox
>> Set VPic.Picture = picTest.Picture

**********************************
Ooops, that line should have read:
Set VPic = picTest
**********************************

>> VPic.CurrentX = 60
>> VPic.CurrentY = 70
>> VPic.FontName = "Tahoma"
>> VPic.FontSize = 24
>> VPic.Print "TEST"
>>
>> picTest is a visible ordinary PictureBox with a loaded image, AutoRedraw
>> =
>> True , Scalemode = Pixels

All I want is to be able to use a virtual PictureBox in the same way as a
real one but without the overhead of actually showing anything. So I want to
take a copy of what is displayed, fart about with the copy but not affect
the original in any way, and then save the resultant picture to a file.
Using a variable as a PictureBox seemed ideal but I cannot get it to work.
I suppose I could work with a StdPicture but I'd still need to copy the
content to a PictureBox or similar because the StdPicture does not expose
any hDC and I really need a hDC for my write Jpeg routine (An entirely self
contained module based on a class by John Korejwa).

>From Deanna:
>You may want to investigate the VB6 DIBSection implementations
>that are floating around the internet.

Already use some of that sauce in the Jpeg stuff however it does seem a bit
of a sledgehammer when I only want to crack a small nut.

Thanks
DaveO



Deanna Earley

unread,
May 8, 2013, 10:31:17 AM5/8/13
to
On 08/05/2013 15:17, DaveO wrote:
>>> Dim VPic As PictureBox
>>> Set VPic.Picture = picTest.Picture
>
> **********************************
> Ooops, that line should have read:
> Set VPic = picTest
> **********************************

That explains it then, you're not copying any picture, you're just using
two different names to talk to the same PictureBox control.

> All I want is to be able to use a virtual PictureBox in the same way as a
> real one but without the overhead of actually showing anything.

Then use a hidden PictureBox.
Note that some graphics operations (to a screen DC) are clipped to the
visible area.
If the control is hidden, they may not work.

> So I want to take a copy of what is displayed, fart about with the
> copy but not affect the original in any way, and then save the
> resultant picture to a file.

Use a proper DIBSection and it will be completely off screen, but you
need to switch to using GDI or wrapper methods.

> Using a variable as a PictureBox seemed ideal but I cannot get it to work.
> I suppose I could work with a StdPicture but I'd still need to copy the
> content to a PictureBox or similar because the StdPicture does not expose
> any hDC and I really need a hDC for my write Jpeg routine (An entirely self
> contained module based on a class by John Korejwa).

No, the StdPicture is a bitmap handle and block of memory, you can
change the underlying memory, but not using nice drawing methods.


>> You may want to investigate the VB6 DIBSection implementations
>> that are floating around the internet.
>
> Already use some of that sauce in the Jpeg stuff however it does seem a bit
> of a sledgehammer when I only want to crack a small nut.

Not really, that's exactly what a DIBSection and DC is, a bitmap and a
drawing surface. Using a full visible PictureBox is the sledgehammer as
it has other stuff and limitations thrown in.

It also makes it fully device independent so it can work on low colour
depth machines (if such a beast exists any more)

DaveO

unread,
May 8, 2013, 10:59:41 AM5/8/13
to

"Deanna Earley" <dee.e...@icode.co.uk> wrote in message
news:kmdnji$m7d$1...@speranza.aioe.org...
>> All I want is to be able to use a virtual PictureBox in the same way as a
>> real one but without the overhead of actually showing anything.
>
> Then use a hidden PictureBox.
> Note that some graphics operations (to a screen DC) are clipped to the
> visible area.
> If the control is hidden, they may not work.

That's what I'm doing now, I thought that I might be able to speed things
up a little.

>> So I want to take a copy of what is displayed, fart about with the
>> copy but not affect the original in any way, and then save the
>> resultant picture to a file.
>
> Use a proper DIBSection and it will be completely off screen, but you need
> to switch to using GDI or wrapper methods.

I also don't want any dependencies over what VB6 normally requires so I'd
rather not use GDI/GDI+. Anyway this is all for a pretty trivial part of the
application, also I suspect that the time I have spent getting it to work
probably far exceeds the time that having the functions integrated will ever
save. Obligatory XKCD reference: http://xkcd.com/1205/


> Deanna Earley (dee.e...@icode.co.uk)
> iCatcher Development Team
> http://www.icode.co.uk/icatcher/

Thanks
DaveO


Deanna Earley

unread,
May 8, 2013, 11:11:00 AM5/8/13
to
On 08/05/2013 15:59, DaveO wrote:
> "Deanna Earley" <dee.e...@icode.co.uk> wrote in message
> news:kmdnji$m7d$1...@speranza.aioe.org...
>> Use a proper DIBSection and it will be completely off screen, but you need
>> to switch to using GDI or wrapper methods.
>
> I also don't want any dependencies over what VB6 normally requires so I'd
> rather not use GDI/GDI+.

GDI is a core part of Win32 and pretty much every win32 app uses it at
some level.

--
Deanna Earley (dee.e...@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

DaveO

unread,
May 8, 2013, 11:21:26 AM5/8/13
to

"Deanna Earley" <dee.e...@icode.co.uk> wrote in message
news:kmdpu0$ssd$1...@speranza.aioe.org...
> On 08/05/2013 15:59, DaveO wrote:
>> "Deanna Earley" <dee.e...@icode.co.uk> wrote in message
>> news:kmdnji$m7d$1...@speranza.aioe.org...
>>> Use a proper DIBSection and it will be completely off screen, but you
>>> need
>>> to switch to using GDI or wrapper methods.
>>
>> I also don't want any dependencies over what VB6 normally requires so I'd
>> rather not use GDI/GDI+.
>
> GDI is a core part of Win32 and pretty much every win32 app uses it at
> some level.

OK, please allow me to rephrase what I said: "I don't see the point of
learning a whole load of stuff I've not used before to replace something
that already works" Did you look at the XKCD, it pretty much sums it up.

Thanks Again
DaveO


Deanna Earley

unread,
May 8, 2013, 11:30:37 AM5/8/13
to
On 08/05/2013 16:21, DaveO wrote:
> "Deanna Earley" <dee.e...@icode.co.uk> wrote in message
> news:kmdpu0$ssd$1...@speranza.aioe.org...
>> On 08/05/2013 15:59, DaveO wrote:
>>> "Deanna Earley" <dee.e...@icode.co.uk> wrote in message
>>> news:kmdnji$m7d$1...@speranza.aioe.org...
>>>> Use a proper DIBSection and it will be completely off screen, but you
>>>> need
>>>> to switch to using GDI or wrapper methods.
>>>
>>> I also don't want any dependencies over what VB6 normally requires so I'd
>>> rather not use GDI/GDI+.
>>
>> GDI is a core part of Win32 and pretty much every win32 app uses it at
>> some level.
>
> OK, please allow me to rephrase what I said: "I don't see the point of
> learning a whole load of stuff I've not used before to replace something
> that already works"

That's not a rephrase, it's a different objection altogether.
You also asked for another method due to problems/limitation of your
current method :)
I just gave you the best method.
I agree it's up to you whether you implement it or not. For us, it was.

> Did you look at the XKCD, it pretty much sums it up.

Of course.

Larry Serflaten

unread,
May 8, 2013, 8:04:32 PM5/8/13
to
DaveO wrote:

> I have a picture in a PictureBox that needs some alteration and then saving,
> easy enough using a hidden PictureBox or two but I'd rather not so I
> wondered about using a PicutreBox in code that's never shown.


If you use a picturebox that isn't shown, is it not in fact, hidden??? :-)

FWIW, my take on images goes something like this:

- Use Image controls to show images on a form
- Use Picture controls to draw on a canvas
- Use the StdPicture object to hold images in memory

So in your case, you'd load a picture into an Image control on the form and use
PaintPicture to copy that image to a hidden Picturebox control for the needed
manipulations and save operation.

LFS

MM

unread,
May 8, 2013, 10:50:40 PM5/8/13
to
Since we're talking about PictureBoxes here, just let me remind
everyone about the transparent PictureBox control available for free
from Thomas Allin's Visual Basic page:
http://www.musiker.nu/objectstudio/VBPage/

Scroll down for the Vemod SeeThroughPictureBox.

It works very well.

MM

Deanna Earley

unread,
May 9, 2013, 4:59:52 AM5/9/13
to
On 09/05/2013 03:50, MM wrote:
> Since we're talking about PictureBoxes here, just let me remind
> everyone about the transparent PictureBox control available for free
> from Thomas Allin's Visual Basic page:
> http://www.musiker.nu/objectstudio/VBPage/
>
> Scroll down for the Vemod SeeThroughPictureBox.

Not really relevant considering the OP was explicitly after a way of
doing off screen manipulation.
In that case, the fact it's see through isn't particularly useful :)
0 new messages