I'm trying to paste a png image with a transparency gradient over another image. Problem: the semi-transparent image doesn't show up at all. I have the image embedded as a resource in my project, and I suspect the problem is that VB is importing that image as a bitmap (found the following in resources.designer.vb):
Friend ReadOnly Property alphamask() As System.Drawing.Bitmap
Get
Dim obj As Object = ResourceManager.GetObject("alphamask", resourceCulture)
Return CType(obj, System.Drawing.Bitmap)
End Get
End Property
But so far, I haven't been able to find a workaround for this. The image, when drawn with
G.DrawImage(My.Resources.alphamask, destRect)
in the form_paint event, doesn't show up at all. By the way, this problem is unique with this one, semi-transparent image. All the other images I'm using, in exactly the same way, work perfectly. Any suggestions?
Related
I'm in an excel vba program and I need to display and create a label for a printer.
Now this printer (Zebra Z4M Plus 300 dpi) is extremely fussy and hard to use.
I can now print to it if I create an image file (png or img) of dimensions 944x406 and put my desired label in an area of 797x396 in the upper left corner of that image file.
My question is about creating said image.
Some 10 years ago I remember that it was possible (in probably vb6) to use image primitives such as lines, polygons, circles and text to a picturebox control.
In Excel I have created a form and created an image control however a look at the functions and properties of this object didn't reveal any function for drawing anything on it !
(P.S. I have now found that this image object has a .picture property, this property has a .handle property and .render function, I must be close to something usable but I can't find it. It seems I could load a picture from a picture file using the LoadPicture function on this picture property)
(Perhaps there are windows api function that will let me draw on this .picture using the .picture.handle ?)
The excel Shape object also didn't have drawing primitives but it did have a .CopyPicture function that would allow me to put the contained image in the clipboard (and then I just need to find a way to save the clipboard content to an image file)
If possible I would like to draw to an object which is contained in the worksheet rather than in a userform.
I am looking for further search keywords, names of objects and function for drawing.
Thank you !
In my application, users are allowed to choose a picture they want and this picture shows up in a picturebox.
I want to know if there was a way so that this picture that they select becomes circular instead of a square?
I want all images they select to be circle shaped.
Is there anyway to do this? Doesn't even have to be a picturebox control, anything that can accomplish this is fine
I tried this with no luck - http://www.codeproject.com/Questions/430531/circle-shaped-picture-box
Not the smartest way, but worked for me in similar task. If your picturebox is fixed size, you can create "mask" which will hide the corners.
Just draw an image in PNG with transparent circle in the middle and make the rest same color as your form. Use this image as Image propperty of each imagebox and set your image as "backgroundImage" property. This way, the image will look circle-shaped.
If you need imageboxes of different size, you can create the circle mask programmatically.
EDIT: If you will prepare a calculation of circle, you can also use it to "crop" the images to circle shape. It all depends on what you want to do with these images later.
Do you need to use them later in circle or rectangle shape?
I want to add a .gif image to a picturebox.
I want user to choose image from a variety of images of different pixels.
if I use
picturebox1.image = image.fromfile("E:\ship1")
then there is no option available of imagelayout unlike backgroundimage.
because of different images pixel only half of image is displayed in my picturebox size.
I don't want to change my picturebox size because in the game that i am working on, it can cause problems.
If i use
picturebox.backgroundimage = image.fromfile("E:\ship1")
but then .gif would not show its animation.
Any suggestion for solution apart from changing size of picturebox cause that would be the last thing to do
I have a picture box. The user can draw different rectangles on it, assuming that the user draws rectangles which go beyond the size of the picturebox, can I uniformly resize the contents to fit the picturebox, even though the image is not saved yet?.
I can only manage to resize content that has been loaded in from and already saved image file. The code that I am using to draw rectangles is as follows:
gr.FillRectangle(Brushes.Black, 0, 0, 2, 75)
Rectangles do appear on picturebox as would be expected.
Also I am unable to save using the following code:
PictureBox1.Image.Save("C:\test\myimage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
The error that I get is:
Object reference not set to an instance of an object.
I use System.IO.MemoryStream when I want to fill pictureboxes with images without saving to the hard drive.
PictureBox1.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData("http://upload.wikimedia.org/wikipedia/commons/e/ec/Banksy.on.the.thekla.arp.jpg")))
This is probably because your PictureBox has no "Image" object assigned to it.
You can find the solution here (first answer): getting image from a picturebox
[Also, you might face issues later on with regards to saving to your root folder (C:). Try to use a folder on your local Desktop, for example, to avoid any access-permission errors.]
Edit:
This is taken from the above link. It appears to me that you have not tried it.
myPictureBox.Image = New Bitmap(myPictureBox.ClientSize.Width, _
myPictureBox.ClientSize.Height)
'Then, when you want to perform some drawing, use a Graphics object from the Image instead of the PictureBox:
Using g As Graphics = Graphics.FromImage(myPictureBox.Image)
' do the drawing '
End Using
I have a picture box on my form, which I add a picture to. This picture has a transparent background, but unfortunately, it seems lost in the picture box... I'm guessing that's because the picture box's background colour property is set to grey (the default). I can't see any option for "transparent" though.
Any idea how I can do it?
Depending on what you are trying to accomplish there's several different ways to go about it.
Some examples are -
Make bitmap transparent
Dim bmp As Bitmap = Bitmap.FromFile("test.bmp")
bmp.MakeTransparent(Color.Magenta) ' magenta in bitmap will be transparent
PictureBox1.Image = bmp
Make the picture box transparent
PictureBox1.BackColor = Color.Transparent
If you really need a transparent image I would suggest not using the picturebox and just render a transparent bitmap directly.
If you want the controls behind the PictureBox to show, ie. you want your image displayed with a transparent background, try drawing straight on the form itself.
Back in the days of VB6 we could do this by hooking onto the Form's "Redraw" event or something...
On most controls in VB, in the Backcolor property of the object, there is an option for transparency. This works fine in VB2008, but in VB2005, you must then set it's .parent property to the object behind (well, in my experience anyways.)
Hope this helps,
I know this is an old topic, but I figured I'd post the solution I came up with for anyone looking for a simple solution for Windows Forms. Say you have PictureBox1 and PictureBox2. You want PictureBox2 to overlay on PictureBox1. Make sure your PictureBox1 background is set to transparent. Then, you can programmatically set:
PictureBox2.Parent = PictureBox1
Magic
Transparent an Image, You can also used Adobe Photoshop to Remove White/Black Background (Watch Tutorial How to Create Transparent Background)
or Use this code below,
PictureBox1.BackColor = Color.Transparent
SetStyle(ControlStyles.SupportsTransparentBackColor, True)