![]() Return BitmapToBitmapSource( ResizeImage(īitmapImageToBitmap( large_icon ), w, h ) ) ScaledIcon simply calls the three helper methods defined above to return a scaled version of the input image: /// /// Scale down large icon to desired size for Revit /// ribbon button, e.g., 32 x 32 or 16 x 16 /// static BitmapSource ScaledIcon( Image.Height, GraphicsUnit.Pixel, wrapMode ) G.DrawImage( image, destRect, 0, 0, image.Width, WrapMode.SetWrapMode( WrapMode.TileFlipXY ) Using( var wrapMode = new ImageAttributes() ) G.PixelOffsetMode = PixelOffsetMode.HighQuality G.SmoothingMode = SmoothingMode.HighQuality G.InterpolationMode = InterpolationMode.HighQualityBicubic G.CompositingQuality = CompositingQuality.HighQuality G.CompositingMode = CompositingMode.SourceCopy Using( var g = Graphics.FromImage( destImage ) ) Var destImage = new Bitmap( width, height ) ĭestImage.SetResolution( image.HorizontalResolution, ResizeImage /// /// Resize the image to the specified width and height. Retval = Imaging.CreateBitmapSourceFromHBitmap( / /// Convert a Bitmap to a BitmapSource /// static BitmapSource BitmapToBitmapSource( Bitmap bitmap ) Public static extern bool DeleteObject( IntPtr hObject ) BitmapImage bitmapImage = new BitmapImage( // new Uri("./Images/test.png", UriKind.Relative)) using( MemoryStream outStream = new MemoryStream() )īitmapEncoder enc = new BmpBitmapEncoder() Įnc.Frames.Add( BitmapFrame.Create( bitmapImage ) ) Here they are one by one: BitmapImageToBitmap /// /// Convert a BitmapImage to Bitmap /// static Bitmap BitmapImageToBitmap( ScaledIcon – return a scaled down icon of desired size for Revit ribbon button.ResizeImage – resize an image to the specified width and height.BitmapToBitmapSource – convert a Bitmap to a BitmapSource.BitmapImageToBitmap – convert a BitmapImage to Bitmap.I finally solved that once and for all by implementing a couple of methods to perform automatic bitmap scaling: They seem to expect a 32 x 32 and 16 x 16 icon, respectively. ![]() Therefore I changed the interface to take an ImageSource and changed the call to this: btnMenu2.Clicked += ((sender, e) DrawingImage.Every time I created a ribbon button, I was faced with the task of creating appropriately scaled icons for it to populate the PushButton large and small image icon properties LargeImage and Image. Instead of passing the ImageWithTouch object (a view) to the Email method you should be just passing an ImageSource. I think what you meant to do was to convert the ImageSource into a Bitmap. In your example you are trying to convert an Image into a Bitmap, but that Image has no Source set, which means it has no picture to convert to a Bitmap. You can convert an ImageSource into a Bitmap. The ImageSource type represents an actual picture. The Image view has a property called Source, which has the type ImageSource. You are all kinds of confused, and I partly blame Xamarin. How do you expect me to help you with this example? The one you've uploaded crashes and doesn't seem to even go through the code path you're talking about. Please upload a complete example that shows what you're describing in this post. Regardless, I don't see anything that would call that code. You need the full code I linked to above. I don't even know what you're trying to do there.Īlso, the code you just quoted (which came from Andrei) is not sufficient to get a Bitmap from an ImageSource. You can't convert an Image into an ImageSource. ![]() This line doesn't even make sense to me: DrawingImage.Source = (ImageSource)convert.ConvertFrom( DrawingImage) at /IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/:1888 at .ButtonRenderer/ButtonClickListener.OnClick () at _0 (object,System.EventArgs) in /Users/akemp/Downloads/GeradorCantadas/GeradorCantadas/Principal.cs:32 at GeradorCantadas.ctor () in /Users/akemp/Downloads/GeradorCantadas/GeradorCantadas/.cs:35 When I run your example and click the button that says "HOMEM" the app crashes here: System.InvalidOperationException: Cannot convert "GeradorCantadas.ImageWithTouch" into ![]()
0 Comments
Leave a Reply. |