This question already has answers here:
How do I save a BitmapImage from memory into a file in WPF C#?
(1 answer)
Uploading Stream to Database
(1 answer)
Closed 9 months ago.
The question: how can I save the image that is the image control (Name Photo) that is in bmp format for the database in SQL Server from UWP and C#?
class.cs
public BitmapImage Picture { get; set; }
Code C# SQL: I would be missing the equal part of the code
cmd.Parameters.Add("#picture", SqlDbType.Image).Value =;
Related
This question already has answers here:
WPF Font: Why are some characters missing?
(5 answers)
Closed 3 years ago.
I am trying to set the Text property of a textbox in WPF with a string containing umlaut characters:
Textbox.Text = "!##$%&*,ÖÄäü";
But the textbox only displays !##$%&*, and omits the umlaut characters.
How to make the umlaut characters to appear?
You could try to save the file with the Unicode (UTF-8 with signature) - Codepage 65001 encoding (File->Save As->Save with Encoding in Visual Studio) or look up the unicode for the character in the Character Map application in Windows.
For ü, it's 00FC for example:
Textbox.Text = "\u00FC";
This question already has answers here:
WPF - How to zoom specific area in an image
(1 answer)
How to effectively crop and scale image data
(1 answer)
Closed 5 years ago.
I'm stuck and I need advice, I've gone down multiple rabbit holes and haven't found any rabbits... I don't know if this is a conversion issue, resolution issue, or I just need to use different object types, or what. I'm new to working with images. Please help me!
I have a WPF application which loads in images of various types, and it loads them as BitmapImage objects. They are displayed in an image control:
<Image Width="70" Height="90" Source="{Binding Path=Source}" />
This application provides the ability for the user to draw a rectangle around part of the image, and then the application saves that rectangle as a separate image to disk. I'm using System.Drawing.Rectangle to store the rectangle object. Here's a code snippet, which leaves me with just a much smaller portion of the image than the actual rectangle is.
Bitmap segment = new Bitmap(item.Width, item.Height);
var g = Graphics.FromImage(segment);
g.DrawImage(source, 0, 0, new Rectangle(item.X, item.Y, item.Width, item.Height), GraphicsUnit.Pixel);
segment.Save(imagePath, ImageFormat.Jpeg);
The problem occurs when I go to write the rectangle out to a file, because Rectangle is compatible with Bitmap, but not with BitmapImage, at least when it comes to sizing. When I load my images into BitmapImage it changes their size with the PixelHeight and PixelWidth properties. It seems to roughly double in size. I don't know why it does that. But BitmapImage is more compatible with WPF, so I'm using that. The straight Bitmap object doesn't have those pixel properties. And the rectangle is like the regular size (not the doubled up Pixel size).
So I tried using CroppedBitmap since that's compatible with BitmapImage, to get the selected image. So I got the size increase ratio and increased my rectangle size by that, to create the CroppedBitmap, but the sizing is a little too small. It's cutting off the outer edges. "item" is my rectangle. Here's the code sample for that. Should I stick with CroppedBitmap and just throw in some padding? Or is there something else I should be doing?
double heightFactor = source.PixelHeight / source.Height;
double widthFactor = source.PixelWidth / source.Width;
CroppedBitmap segment = new CroppedBitmap(source, new Int32Rect(item.X, item.Y, Convert.ToInt32(Math.Ceiling(item.Width * widthFactor)), Convert.ToInt32(Math.Ceiling(item.Height * heightFactor))));
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to Skin an Win32 Application
I'm trying to learn to design a application, but I'm stuck.
For a example, how would I code/get this kind GUI ( Background image, navigation, the engineering icon in the up left corner, styled minimize and quit icons ... etc ) in C/Win32API as represented on that picture?
Thanks.
This is called "skinning".
See this article for example: (Flipcode)
All you have to do is to create the HBITMAP object (load it from Resource or from File) and the use the SelectObject to choose it as a background.
I add a folder of image files in my silverlight application. I want to put name of these files (jpg file) to arraylist.
How can I access to these files in silverlight 3?
You could use the openFileDialog class if you are accessing files on your server.
http://msdn.microsoft.com/en-us/library/cc221415%28v=vs.95%29.aspx
This gives a good intro to how it works. You're going to have to write the logic of changing the stream into a BitmapImage. But that only 3 lines of code. I'll supply it if you want it.
However if you just want to access images within the application all you need to do is accesses them within the application by creating them as a new bitmapimage:
Image image = new Image();
image.Source = new BitMapImage(new Uri("imagesFolder/yourImageName.jpg",UriKind.RelativeOrAbsolute));
//set the height and width properties afterwards
Let say I have application menus in a database with their icon images (binary data). I extract those menus with the icons being byte[] type. However if there's no icon set, then I would like to use default icon which comes not from database, but from xap (inside Resources folder). To display icons coming from database I use IConverter (byte[] to image), which is based on the code of the following question:
Silverlight 4.0: How to convert byte[] to image?
To be able to use my byte[]-to-image IConverter, I would also like to convert my default icon to byte[], which comes from xap. How I can do that? The following question suggested to use WriteableBitmap class, but I don't know how to create WriteableBitMap from the xap source:
Silverlight: image to byte[]
I may be miss understanding the question here (perhaps more details about your converter are required here), but if you converter class just returns an image based on its bytes, cant you just test for null bytes from the DB, then return your default image?
public class MyConveter : IConverter {
public Image ConvertImage(byte[] bytes) {
if (bytes == null) return GetDefaultImage();
else return ConverterBytesToImage(bytes);
}
}
this way you simply return an image as the method declaration, and the implementation handles the null bytes case.
Is this on the right track?
As your default icon is a resource, you can open it as a ResourceStream and just read it in as bytes.
Would that meet your requirements?