I'm drawing an image on a PictureBox using Graphics.DrawImage() method. The background of the drawn image should be transparant so that it's not drawn on top of the the other things made by grapics. The code looks like this:
Image Icon = Image.FromFile(#"C:\\Dieroller\Die Icons\d4.jpg");
//Icon.SetColorToTransparant(White); //This is what I which would work.
Graphics.DrawImage(Icon, Location);
Any sugestions?
Related
I'm working on a new UI-element in an vb6 programm. I need to place pictures dynamically on 2 diffenent colored background lines:
I tried out two different ideas but none of them is working:
Idea 1
I used image control and assigned an image to the control. Then I set left, top, with and hight properties to values where I want to place the image. Image was places at correct position but not in foregound on a frame but in background (behind coloured frame).
Can anyone tell me how I can place an image control in foreground (on green coloured frame)? I need to place these image controlls dynamically from code in running program.
Idea 2
In second sulution I tried to use picturebox instead of image control. Picturebox can be placed on colored background (frame) without any problems.
Here the problem is that loaded picture has to be scaled to size of picturebox picture property. Picture is loaded to picturebox by following code: Picture.Picture = LoadPicture("F:\img.JPG")
Does anyone know how I can scale this img to size of picturebox?
Can anyone help me to follow up one of the solutions. In principle I would prefere to use Image controls if it is polible to place them in foreground on frame.
I'm going to guess that after creating the image control, you are moving it onto the Frame. If so, this is why the control is behind the Frame. You really want the image to be inside the frame. The key to do this is to set the Container property.
Dim img As Image
Set img = Me.Controls.Add("VB.Image", "Image1")
If Not img Is Nothing Then
img.Move 200, 200, 400, 400
img.Stretch = True
img.Picture = LoadPicture("your image.jpg")
Set img.Container = Frame1
img.Visible = True
End If
designer give me picture like this
But when I use drawInRect API draw the picture in context, the picture is like this
The size of the rect is just the size of the image.And the image is #1x and #2x.
the difference is very clear, the picture is blurry and there is a gray line in the right of image, and My imac is retina resolution.
================================================
I have found the reason,
[self.headLeftImage drawInRect:NSMakeRect(100,
100,
self.headLeftImage.size.width,
self.headLeftImage.size.height)];
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
CGContextSaveGState(context);
CGContextTranslateCTM(context, self.center.x , self.center.y);
[self.headLeftImage drawInRect:NSMakeRect(100,
100,
self.headLeftImage.size.width,
self.headLeftImage.size.height)];
CGContextRestoreGState(context);
And in the first draw the image will not blur, but after translate the image is blurry. Just like the picture:
The problem is that you're translating the context to a non-integral pixel location. Then, the draw is honoring your request to put the image at a non-integral position, which causes it to be anti-aliased and color in some pixels partially.
You should convert the center point to device space, integral-ize it (e.g. by using floor()), and then convert it back. Use CGContextConvertPointToDeviceSpace() and CGContextConvertPointToUserSpace() to do the conversions. That does the right thing for Retina and non-Retina displays.
I am a beginners so please answer me in detail so that i will be able to do it.
I am making a simple application in visual basics 2010.
I have two picture boxes in my form one is for background and another one is the object which will move... i have to make the second picture box transparent.
I have a png image to insert on that box which is of transparent background.
Please help me ..
Here, the important thing is the parent. You can load a transparent picture to the PictureBox (Note: You can load a BMP file, as well). You can define any color as transparent. See the picture.
In this project:
The parent of Panel1 is Form1.
The parent of PictureBox1 is Panel1.
The parent of PictureBox2 is PictureBox1.
The parent of PictureBox3 is Form1.
If you make PictureBox1 transparent, then you will see it is only transparent for Panel1 (which is PictureBox1's parent). In other words, you can see the Panel1's Background under the transparent color.
If you make PictureBox3 transparent, then you will see it is only transparent for Form1 (which is PictureBox3's parent). In other words, you can see the Form1's Background under the transparent color.
That's why, as much as I understand, in your project the parent of PictureBox2 should be PictureBox1. You can load (or draw) a picture for PictureBox1. Then you can load your animation picture to PictureBox2 which has a transparent color.
Please see the code below:
...
PictureBox2.BackColor = Color.Transparent
PictureBox2.Size = New Size(1042, 1474)
PictureBox2.Location = New Point(55, 0)
Dim bmp As Bitmap
bmp = (System.Drawing.Image.FromFile("empty.bmp"))
bmp.MakeTransparent(Color.FromArgb(255, 255, 255))
PictureBox2.Image = bmp
...
Hope, it helps.
I am using a CodeJock ImageManager component to hold a variety of images. I want to put one of these images into a FlexGrid Cell.
The Images I have are Png format and have transparent backgrounds so when I load the image into the grid like so:
Grid.Cell(flexcpPicture, 123, 4) = _
ImageManagerControl.Icons.GetImage(ImageNum, 16).CreatePicture(xtpImageNormal)
the background which in the original image was transparent is now black:
(the same happens if I load the image into a PictureBox using the above method)
According to the documentation CreatePicture returns an StdPicture object, is there some way I can convert this image (using BitBlt perhaps) so that the black is white? I'm not sure if this even possible?
I only need to do this with about three images so if I have to load them into an ImageList or something else first that would be ok.
I'm not sure if this helps at all, but I've been playing around with the PictureBox. I put two picture boxes on a form, put a bmp file (this only works with bmp files, so it might not be helpful to you), and did this:
Picture2.PaintPicture Picture1.Picture, 0, 0, opcode:=vbNotSrcCopy
Which successfully inverted the bitmap. Here are the RasterOp constants: http://msdn.microsoft.com/en-us/library/aa243035(v=vs.60).aspx
I'm creating NSOutlineView with custom cell class (extending NSTextFieldCell) which should display image-based badge (something like in Mail.app while working offline).
Is this approach appropriate? I've created NSRect with oval shape inside (with bezierPathWithRoundedRect:xRadius:yRadius: method) which is filled with color depending if window is active etc. I've prepared a image with a symbol I want to dispay (grey on transparent background) and draw it inside a rect using drawInRect:fromRect:operation:fraction: method. I'm able to choose such a NSCompositingOperation to have an image displayed properly when background is blue or grey but not on white background.
May it be related to the brightness of the image is (or is it another image-related problem) or maybe should I do something totally different?