NET. utils. registerImageByImageSource (string name, ImageSource imageSource, double width, double height). You should blame Microsoft for this problem, why does the Image have to be bound to the source and displayed on Silverlight to obtain the width and height information? When the component is not displayed, you can only get 0 for the width and height of the image.
. NET. utils. registerImageByImageSource (string name, ImageSource imageSource, double width, double height). You should blame Microsoft for this problem, why does the Image have to be bound to the source and displayed on Silverlight to obtain the width and height information? When the component is not displayed, you can only get 0 for the width and height of the image.
Internal static void RegisterPNGImage (string name, Uri uri)
{
StreamResourceInfo resourceInfo = Application. GetResourceStream (uri );
If (resourceInfo! = Null & resourceInfo. Stream! = Null)
{
BitmapImage image = new BitmapImage ();
# If SILVERLIGHT
Image. SetSource (resourceInfo. Stream );
# Else
Image. BeginInit ();
Image. StreamSource = resourceInfo. Stream;
Image. EndInit ();
# Endif
ResourceInfo. Stream. Position = 0;
Byte [] header = new byte [8];
ResourceInfo. Stream. Read (header, 0, header. Length );
If (header [0] = 0x89 &&
Header [1] = 0x50 & // P
Header [2] = 0x4E & // N
Header [3] = 0x47 & // G
Header [4] = 0x0D & // CR
Header [5] = 0x0A & // LF
Header [6] = 0x1A & // EOF
Header [7] = 0x0A) // LF
{
Byte [] buffer = new byte [16];
ResourceInfo. Stream. Read (buffer, 0, buffer. Length );
Array. Reverse (buffer, 8, 4 );
Array. Reverse (buffer, 12, 4 );
Double width = BitConverter. ToInt32 (buffer, 8 );
Double height = BitConverter. ToInt32 (buffer, 12 );
ResourceInfo. Stream. Close ();
ImageUtils. RegisterImageAsset (name, new ImageAsset (image, width, height ));
Return;
}
ResourceInfo. Stream. Close ();
}
New Exception ("Can not load PNG image'" + name + "'uri:" + URI );
}
I am here to serve as TWaver for Microsoft last year. NET has already started to pre-state and use the customer's apologies in the project in beta. We have not completely done DRY, but the TWaver Development Team, which has always adhered to the principle of minimizing the workload of users, has officially started TWaver. NET 1.0 provides a more comfortable RegisterPNGImage (string name, Uri uri) function when it is released. Yes, you don't have to tell TWaver width or height. TWaver will automatically get it, as for how to get a lot of people are very interested, I will not explain the following implementation of the Code principle is very simple, in short, all the way to Rome, Silverlight does not provide us can go out of their own way