Click here to Skip to main content
15,900,675 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: multiple big images on canvas in WPF - rendering problems Pin
gruberdominik10-May-10 22:36
gruberdominik10-May-10 22:36 
QuestionHelp Needed Pin
Xerox44-May-10 0:21
professionalXerox44-May-10 0:21 
AnswerRe: Help Needed Pin
Pete O'Hanlon4-May-10 1:23
mvePete O'Hanlon4-May-10 1:23 
Questionrandom image appear Pin
yuripon3-May-10 15:32
yuripon3-May-10 15:32 
AnswerRe: random image appear Pin
Kunal Chowdhury «IN»9-May-10 0:40
professionalKunal Chowdhury «IN»9-May-10 0:40 
QuestionWPF Browser Application Error - System.ArgumentException: Value does not fall within the expected range. Pin
Polymorpher3-May-10 14:38
Polymorpher3-May-10 14:38 
AnswerRe: WPF Browser Application Error - System.ArgumentException: Value does not fall within the expected range. Pin
prabhu_thil23-Nov-10 7:16
prabhu_thil23-Nov-10 7:16 
QuestionWriteableBitmap problem Pin
#realJSOP3-May-10 2:54
professional#realJSOP3-May-10 2:54 
Using SL3/VS2008:

I'm (still) trying to render text on a bitmap. Tim Yen suggested using WriteableBitmap, and even that doesn't seem to work for me. I've tried it two different ways:

Label label = new Label();
label.Style = this.Resources["TitleBaseStyle"] as Style;
label.Content = "WHMC";
<br />
WriteableBitmap bmp = new WriteableBitmap(60, 60);
bmp.Render(label, new TranslateTransform()); // I also tried a null Transform here
bmp.Invalidate();
<br />
Image image = new Image();
image.HorizontalAlignment = HorizontalAlignment.Center;
image.VerticalAlignment = VerticalAlignment.Center;
image.Width=60;
image.Height=60;
image.Source = bmp;
this.testImage.Child = image;


...and...

Label label = new Label();
label.Style = this.Resources["TitleBaseStyle"] as Style;
label.Content = "WHMC";
<br />
WriteableBitmap bmp = new WriteableBitmap(label, new TranslateTransform());
<br />
Image image = new Image();
image.HorizontalAlignment = HorizontalAlignment.Center;
image.VerticalAlignment = VerticalAlignment.Center;
image.Width=60;
image.Height=60;
image.Source = bmp;
this.testImage.Child = image;


In the interest of completeness, here's the label's custom style:

<Style x:Key="TitleBaseStyle" TargetType="dataInput:Label">
	<Setter Property="Width" Value="60" />
	<Setter Property="Height" Value="30" />
	<Setter Property="Background" Value="Black" />
	<Setter Property="Foreground" Value="White" />
	<Setter Property="FontSize" Value="17" />
	<Setter Property="Padding" Value="0" />
	<Setter Property="HorizontalAlignment" Value="Center" />
	<Setter Property="HorizontalContentAlignment" Value="Center" />
	<Setter Property="VerticalAlignment" Value="Center" />
	<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>


...and here's the container for the image:

<Border x:Name="testImage" BorderBrush="Black" Background="Red" BorderThickness="1" Margin="10"/>


Neither method results in an Image with anything visible in it (all the pixels in the WriteableBitmap object are null). This is driving me insane. What the hell am I doing wrong?

Just to make sure the label was being created as expected, I also did this, and it is displayed as expected:

Label label = new Label();
label.Style = this.Resources["TitleBaseStyle"] as Style;
label.Content = "WHMC";

this.testImage.Child = label;


I'm at a total loss...

EDIT ==================

I downloaded the WriteableBitmapEx assembly from codeplex because it contains a Clear(Color) method (like the GDI Bitmap class does). If I don't call bmp.Render(label), the image does in fact get displayed. If I put the bmp.Render(label) back into the code, the image does NOT display.

Side note: If I call bmp.Clear(Color.Transparent) (and remove the Render(label) line), the rendered image has a whiteground, despite the Image object being placed in a red-filled Border container.

WTF?
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

AnswerRe: WriteableBitmap problem Pin
Rama Krishna Vavilala3-May-10 4:34
Rama Krishna Vavilala3-May-10 4:34 
GeneralRe: WriteableBitmap problem Pin
#realJSOP3-May-10 5:06
professional#realJSOP3-May-10 5:06 
AnswerRe: WriteableBitmap problem Pin
42774803-May-10 10:27
42774803-May-10 10:27 
GeneralRe: WriteableBitmap problem Pin
42774803-May-10 11:11
42774803-May-10 11:11 
GeneralRe: WriteableBitmap problem Pin
Tim Yen3-May-10 14:57
Tim Yen3-May-10 14:57 
AnswerRe: WriteableBitmap problem Pin
#realJSOP4-May-10 7:54
professional#realJSOP4-May-10 7:54 
QuestionRTF Encoding Pin
Adriaan Davel3-May-10 2:09
Adriaan Davel3-May-10 2:09 
AnswerRe: RTF Encoding Pin
Abhinav S3-May-10 5:13
Abhinav S3-May-10 5:13 
GeneralRe: RTF Encoding Pin
Adriaan Davel3-May-10 18:56
Adriaan Davel3-May-10 18:56 
QuestionEvent calendar Pin
Peace ON3-May-10 0:53
Peace ON3-May-10 0:53 
AnswerRe: Event calendar Pin
Abhinav S3-May-10 5:09
Abhinav S3-May-10 5:09 
AnswerRe: Event calendar Pin
Peace ON3-May-10 21:18
Peace ON3-May-10 21:18 
QuestionWPF: Context-menu for Row and Header of DataGrid Pin
Prasoon Chaudhary2-May-10 20:34
Prasoon Chaudhary2-May-10 20:34 
AnswerRe: WPF: Context-menu for Row and Header of DataGrid Pin
Prasoon Chaudhary2-May-10 21:22
Prasoon Chaudhary2-May-10 21:22 
GeneralRe: WPF: Context-menu for Row and Header of DataGrid Pin
Pete O'Hanlon3-May-10 2:41
mvePete O'Hanlon3-May-10 2:41 
QuestionCustom SelectedItem in ListView Pin
Saksida Bojan1-May-10 9:30
Saksida Bojan1-May-10 9:30 
AnswerRe: Custom SelectedItem in ListView Pin
Pete O'Hanlon1-May-10 9:45
mvePete O'Hanlon1-May-10 9:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.