Picturebox透明度无法在visual studio中使用! ! [英] Picturebox transparency not working in visual studio! !

查看:86
本文介绍了Picturebox透明度无法在visual studio中使用! !的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我在photoshop中创建了几个PNG并将它们上传到我的窗体。我想将一张图片放在另一张图片上,以创建一个包含多个图层的图片。我正在制作一个超级简单的披萨制作程序,因此当您选择带有顶部选择的盒子时,顶部会出现在披萨的底部。



出于某种原因,虽然我无法获得透明度。当我将每个图片框的背景颜色设置为透明时,它只需要采用表单背景颜色工作(如果我没有多个图层就可以了)但是当我尝试将每个图像放在彼此的顶部时,它就能完成工作并且每个顶部图像周围都有一个与背景颜色相匹配的框!



我也尝试过手动设置它,但是没有运气!请帮助!!



ps我是Visual Studio的新手和初学者,所以请放轻松我!



我的尝试:



public Pizza_Form()

{

InitializeComponent();

pizzabase.BackColor = Color.Transparent;

pepperoni.BackColor = Color.Transparent;

spinach.BackColor = Color.Transparent;

pineapple.BackColor = Color.Transparent;

}

Hi!

I created a few PNGs in photoshop and uploaded them to my windows form. I want to place one picture over the other to create a picture with multiple layers. I'm making a super simple pizza maker program so when you select a box with a topping selection the topping appears onto of the base of the pizza.

For some reason though I can't get the transparency to work. When I set the background color of each picturebox to transparent it "works" by just taking the forms background color (if i didnt have multiple layers this would be fine) but when I try and put each image on top of each other it doest work and each topping image has a box around it matching the background color!

I also tried setting it manually like below but no luck! PLEASE HELP!!

p.s I am new and very beginner at Visual Studio so please go easy on me!

What I have tried:

public Pizza_Form()
{
InitializeComponent();
pizzabase.BackColor = Color.Transparent;
pepperoni.BackColor = Color.Transparent;
spinach.BackColor = Color.Transparent;
pineapple.BackColor = Color.Transparent;
}

推荐答案

这是关于质量,尝试从photoshop发布您的图像作为透明图像然后使用它。
It's all about the quality , try to release your image from photoshop as a transparent image then use it.


请参阅我对该问题的评论。也许,我实际上可以理解你想要达到的目标。



解决方案的基本形式非常简单。问题是:你正在使用 PictureBox 这样的东西。由于某种原因,这种近乎无用的控制也成为了形式中最被滥用的控件。它的设计只是为了完成最简单的工作:显示静态图像。但是很多误解造成了一种印象,即这种控制的唯一目的是阻止解决像你这样的问题的尝试。一旦有人试图叠加一些图形元素,引入一些动作或交互行为,这种控制,而不是帮助,开始添加最荒谬的麻烦。同时,当你做一件简单的事情时,所有这些问题都会很快得到解决:摆脱这种控制。



怎么样?请查看我过去的答案:

在其中附加图片图片框 [ ^ ],

如何从旧图纸中清除面板 [ ^ ],

在C#中绘制一个矩形 [ ^ ]。



关于图形渲染的更多答案:

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ]。



现在,返回对你的情况。现在你知道如何渲染图形了。您的图层以简单的方式创建:首先渲染下层,然后渲染顶层。为避免闪烁,请使用优化双缓冲。关键是:为顶部元素创建PNG时,必须在显示背景的部分中使用透明像素。每个非废话图形编辑器都可以做到(甚至Photoshop :-))。忘记控制 BackColor ;这完全是无关紧要的。



现在,为什么我说的基本形式。因为以高质量的方式做这个技巧是非常困难的,在我们讨论的水平上 - 只是不可能。每位经验专家或艺术家都会立即发现假货。只有非常详细的3D建模才能获得高质量的结果,但这是非常昂贵的技术。我可以告诉你原因。


当你在白板或棕色砧板上拍摄一些橄榄时,背景会在每个橄榄果实上留下颜色反射,每个橄榄果实都会在盘子/板上留下颜色反射,那里也会有来自周围物体的反射。当您剪切(使透明)某些背景像素时,您将创建可见的像素化。在原始图像中,每个像素都携带来自背景和前景的颜色并平滑像素,但是你会破坏它。如果使用模糊选择来平滑它,则会在边界像素上放置一些背景颜色。而且,无论你做什么,每个水果上都会看到背景反射。然后将它移动到披萨背景,外来到原始图像中使用的背景。忘记逼真的照片。



我们希望饥肠辘辘的披萨吃的人在订购披萨时不会太在意。 :-)



-SA
Please see my comment to the question. Probably, I actually can understand what you want to achieve.

The solution, in its basic form, is extremely easy. The problem is: you are using such thing as PictureBox. By some reason, this near-useless control also became the most misused control in Forms. It was designed just to do the simplest work: showing static images. But a lot of misunderstanding created an impression that the sole purpose of this control is to block the attempts to solve the problems like yours. As soon as some try to superimpose some graphical elements, introduce some motion or interactive behavior, this control, instead of helping, starts adding most ridiculous hassles. At the same time, all such problems are solved very quickly when you do simple thing: get rid of this control.

How? Please see my past answers:
Append a picture within picturebox[^],
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^].

More answers on graphics rendering:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

Now, back to your case. Now you know how to render graphics. Your layers are created in a simple way: you first render the lower layer, and then top layer. To avoid flicker, use optimized double buffering. Here is the key: when you create a PNG for a topping element, you have to use "transparent" pixels in the parts where the background is shown. Every non-nonsense graphics editor can do it (even Photoshop :-)). Forget control BackColor; this is totally irrelevant.

Now, why did I say in its basic form. Because doing this trick in a quality way is very difficult, on the level we discuss — just impossible. Every experience expert or artist will spot the fake in no time. Only very detailed 3D modeling can achieve high-quality results, but this is extremely expensive technology. I can give you an idea why.

When you photograph some olives on white plate, or brown cutting board, the background will leave color reflexes on each olive fruit, and each olive fruit will leave color reflexes on the plate/board, where there will be also the reflexes from some surrounding objects. When you cut out (make transparent) some background pixels, you will create visible pixellation. In original image, each pixel carries colors from both background and foreground and smooths pixels, but you will destroy it. If you use fuzzy selection to smooth it, you will let some background colors on the boundary pixels. And, no matter what you do, background reflexes will be visible on each fruit. And then you move it to the pizza background, "foreign" to the background used in original image. Forget about photo-realistic image.

Let's hope that hungry pizza eaters won't care too much when they order pizza. :-)

—SA


这篇关于Picturebox透明度无法在visual studio中使用! !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆