Custom capture size using Microsoft Expression Encoder - c#

I have lines of C# code with which I am able to record screen.
But I cannot find a workaround in order to determine custom video output size.
My screen resolution is 1920x1080, although i try to assign new size for the record It remains unchanged.
(Library: Microsoft Expression Encoder, all dependencies are included)
The code I used in Button click event:
ScreenCaptureJob _screenCaptureJob = new ScreenCaptureJob();
Rectangle _screenRectangle = Screen.PrimaryScreen.Bounds;
_screenCaptureJob.CaptureRectangle = _screenRectangle;
_screenCaptureJob.ScreenCaptureVideoProfile.Size = new Size(600, 400); //By doing this Is it supposed to resize original size to 600x400 pixels?
_screenCaptureJob.ScreenCaptureVideoProfile.AutoFit = true;
_screenCaptureJob.ShowFlashingBoundary = false;
_screenCaptureJob.ScreenCaptureVideoProfile.FrameRate = 20;
_screenCaptureJob.CaptureMouseCursor = true;
_screenCaptureJob.ScreenCaptureVideoProfile.SmoothStreaming = true;
_screenCaptureJob.ScreenCaptureVideoProfile.Quality = 20;
_screenCaptureJob.OutputScreenCaptureFileName = string.Format(#"C:\test.wmv");
if (File.Exists(_screenCaptureJob.OutputScreenCaptureFileName))
{
File.Delete(_screenCaptureJob.OutputScreenCaptureFileName);
}
_screenCaptureJob.Start();
Thanks in advance!

What you need to do is to set the _screenRectangle to your custom dimensions:
_screenCaptureJob.CaptureRectangle = new Rectangle(0, 0, 600, 400);
The screen recording size can be left unassigned.
Greetings,
Nikolay

Related

How can I get the object of effect-applied source

I applied customized pixel-shader effect to an image.
var eff = new Shaders.PixelateEffect();
eff.HorizontalPixelCounts = 15;
eff.VerticalPixelCounts = 15;
IMG1.Effect = eff;
Then I tried to merge and overlay between the effect applied image(IMG1) and another image.(IMG2)
But, IMG1.Source bring me an original image.
ImageUtils.OverlayingImages(IMG1.Source, IMG2.Source, x, y);
How can I get an updated image source?
it happened same when I rotate the image.
Do I need to capture the image with RenderTargetBitmap?
Thank you in advance.
I've solved it like this with RenderTargetBitmap. anyway, thank you for the comments.
var eff = new Shaders.PixelateEffect();
eff.HorizontalPixelCounts = 15;
eff.VerticalPixelCounts = 15;
BitmapSource bitmap = (BitmapSource)IMG1.Source;
var r = new Rectangle();
r.Fill = new ImageBrush(bitmap);
r.Effect = eff;
Size sz = new Size(bitmap.PixelWidth, bitmap.PixelHeight);
r.Measure(sz);
r.Arrange(new Rect(sz));
var rtb = new RenderTargetBitmap(bitmap.PixelWidth, bitmap.PixelHeight, 96, 96
, PixelFormats.Default);
rtb.Render(r);
// here's the updated source with the custom effect.
IMG1.Source= ImageUtils.RenderTargetBitmapToBitmap(rtb);

zxing.net c# can't change the width of the barcode in a flowdocument

I'm using visual studio c# and zxing.net library to encode some numbers then print it using flowdocuments.
first i used the BarcodeWriter class in zxing.net to save it as a bitmap then I transformed it into a BitmapImage through this method :
private BitmapSource Bitmap2BitmapImage(Bitmap bitmap)
{
BitmapSource i = Imaging.CreateBitmapSourceFromHBitmap(
bitmap.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
return i;
}
I got it from a thread in here, then I added it to the flowdocument through InlineUIContainer .
This is the code :
public void Print(string[] strArray)
{
System.Windows.Controls.Image barcodeimg = new System.Windows.Controls.Image();
BarcodeWriter writer = new BarcodeWriter();
writer.Format = BarcodeFormat.CODE_128;
writer.Options.PureBarcode = true;
writer.Options.Width = 40;
writer.Options.Height = 6;
MessageBox.Show(strArray[1].ToString());
string BID = strArray[1];
Bitmap mmm = writer.Write(BID.ToString());
FlowDocument flowDoc = new FlowDocument();
Section sec = new Section();
flowDoc.ColumnWidth = 2000;
int x = Properties.Settings.Default.X;
int y = Properties.Settings.Default.Y;
int fontSize = Properties.Settings.Default.fontSize;
sec.Padding = sec.Margin = new Thickness(x,y,0,0);
sec.TextAlignment = TextAlignment.Center;
sec.FontSize = fontSize ;
double lineH = Properties.Settings.Default.LineHighet;
barcodeimg.Source = Bitmap2BitmapImage(mmm);
InlineUIContainer container = new InlineUIContainer(barcodeimg);
container.FontStretch = FontStretches.ExtraCondensed;
Paragraph paragraph = new Paragraph(container);
sec.Blocks.Add(paragraph);
flowDoc.Blocks.Add(sec);
PrintDialog dialog = new PrintDialog();
IDocumentPaginatorSource idpSource = flowDoc;
dialog.PrintDocument(idpSource.DocumentPaginator,"job1");
}
The problem is the printed barcode width won't change, it changes a little bit when i change numbers but not even close to what I'm looking for.
Here is different tries of different sizes, you can see the height changes but the width is almost the same.
http://i.stack.imgur.com/UZsSm.jpg
I'm new here so excuse me for any mistakes.
Thanks.
probably to late but...
Barcodes are just a set of black bars with some white spaces between and the thickness of black bars and the white space between them is what defines the digits.
That beeing said, proportions must be kept.
When you are setting the width and height of "writer.Options", you are realy just setting the grid resolution of the barcode. Try to set to 800 x 600 (or more) and you see that the width will not change, you will only get better image quality.
I dont know how you`re printing the barcode, but probably your problem resides there and not on the barcode construction.

Add extra white space to a scanned image using kofax image controls

What I'm After:
I'm trying to create an extra 1/4 inch of white space to be appended to the TOP of the image during the scanning process.
Using the Kofax Image Controls Toolkit is it possible within one of the following events to add extra white space to the top of the image when scanning?
_PageStart
_PageEnd
_PageAnnotate
_PageDone
Most of the properties available are read only... I know I can set the scan size in the beginning to say 14 inches and when scanning an 11 inch document I will get my extra 3 inches at the bottom of the image. I want to achieve the same principle but at the top of the document and only about a quarter of an inch tall.
So in all the research I did trying to make this possible I came to the conclusion it is in fact not possible...
The only drawbacks about this method were the speed issues after the fact. It did end up slowing down things a good bit.. Hope this helps someone else! Upvote if it helps you please. ;)
What I ended up doing is not using the _PageAnnotate event raised by the Kofax Image Controls and in turn I ended up turning off that event by setting .hDCCreate = false on the Kofax Scan control. Not creating a DC when scanning speeds up the process a little bit not bogging down the processor with all the uncompressing and compressing of the image.
Instead of using the built in Kofax Image Controls event _PageAnnotate I used the _PageDone event and from there used native c# objects/functions to achieve what I was after. Below is the code I ended up with.
if (!Imaging.AnnotateImage(sImageFileName, "This is my annotation..."))
{
Debug.WriteLine("Scan Error! Could not annotate the image.");
}
The code for the class I made called 'Imaging.cs'...
static class Imaging
{
public static bool AnnotateImage(string sFilePath, string sText)
{
try
{
// Get an ImageCodecInfo object that represents the TIFF codec.
ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/tiff");
Encoder myEncoder = Encoder.Compression;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT4);
myEncoderParameters.Param[0] = myEncoderParameter;
//Create some global variables
Point pointPosition = new Point(0, 0);
PointF pPos = new PointF((float)pointPosition.X, (float)pointPosition.Y);
Bitmap newBmp;
Graphics g;
Font fNewFont;
SizeF sizeTextSize;
Rectangle rectTextSize;
//Set inital width and height variables
int iW;
int iH;
int iAnnotationH = 44;
using(Image iSource = Image.FromFile(sFilePath))
{
iW = iSource.Width;
iH = iSource.Height;
//Increase the height of the image
iH += iAnnotationH;
//Create the new bitmap object
newBmp = new Bitmap(iW, iH);
newBmp.SetResolution(200.0F, 200.0F);
g = Graphics.FromImage(newBmp);
g.Clear(Color.White);
g.DrawImageUnscaled(iSource, 0, iAnnotationH, iW, iH);
//Create the font object to draw the annotation text
fNewFont = new Font("Verdana", 12);
//Get the size of the area to be drawn then convert it to a rect
sizeTextSize = g.MeasureString(sText, fNewFont);
rectTextSize = new Rectangle(pointPosition.X, pointPosition.Y, (int)sizeTextSize.Width, (int)sizeTextSize.Height);
//Draw a white rect
g.FillRectangle(Brushes.White, rectTextSize);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
g.DrawString(sText, fNewFont, Brushes.Black, pPos);
}
//Save the changed image
newBmp.Save(sFilePath, myImageCodecInfo, myEncoderParameters);
}
catch
{
return false;
}
return true;
}
static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
}

Centered and scrolled PictureBox in WinForms

I'm developing a WinForms application and can't figure out how to resolve an issue.
I need to show an image in a Form. Because the image can be arbitrarily large, I need scrollbars on the picturebox containing the image so the user can see it entirely.
Googling around I found out the best way to achieve this is to add the PictureBox as a Child Control of a Panel, and making the Panel autosizable and autoscrollable.
I did that programatically since using the designer I was unable to insert the picturebox as a child control of the panel.
The problem I'm now facing is that I can't seem to be able to center and scroll the picturebox at the same time.
If I put the anchor of the picturebox to top,left,bottom,right, the scrollbars are not shown and the image displayed is strange, if I put back the anchor to only top-left, the image is not centered.
Is there any way to do both at the same time?
Here's the code for my Panel and Picturebox:
this.panelCapturedImage = new System.Windows.Forms.Panel();
this.panelCapturedImage.SuspendLayout();
this.panelCapturedImage.AutoScroll = true;
this.panelCapturedImage.AutoSize = true;
this.panelCapturedImage.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.panelCapturedImage.Controls.Add(this.pictureBoxCapturedImage);
this.panelCapturedImage.Location = new System.Drawing.Point(0, 49);
this.panelCapturedImage.Name = "panelCapturedImage";
this.panelCapturedImage.Size = new System.Drawing.Size(3, 3);
this.panelCapturedImage.TabIndex = 4;
this.pictureBoxCapturedImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBoxCapturedImage.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCapturedImage.Name = "pictureBoxCapturedImage";
this.pictureBoxCapturedImage.Size = new System.Drawing.Size(0, 0);
this.pictureBoxCapturedImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBoxCapturedImage.TabIndex = 0;
this.pictureBoxCapturedImage.TabStop = false;
this.panelCapturedImage.Controls.Add(this.pictureBoxCapturedImage);
And here's where I set the image:
public Image CapturedImage
{
set
{
pictureBoxCapturedImage.Image = value;
pictureBoxCapturedImage.Size = value.Size;
}
}
For the PictureBox, set SizeMode = AutoSize, Anchor it Top, Left, and set its Location to 0, 0.
Set Panel.AutSize to False and Panel.AutoScroll to True.
When you set the PictureBox.Image property, it will auto-size to the size of the image. You can then use that size to set the panel's AutoScrollPosition property:
public Image CapturedImage
{
set
{
pictureBoxCapturedImage.Image = value;
panelCapturedImage.AutoScrollPosition =
new Point {
X = (pictureBoxCapturedImage.Width - panelCapturedImage.Width) / 2,
Y = (pictureBoxCapturedImage.Height - panelCapturedImage.Height) / 2
};
}
}
If the image is smaller then then panel's size, it will remain in the upper left corner. If you want it centered within the panel, you'll have to add logic to set its Location appropriately.
Based on earlier answers I was able to create this full example:
private void testShowPictureBox()
{
/* format form */
Form frmShowPic = new Form();
frmShowPic.Width = 234;
frmShowPic.Height = 332;
frmShowPic.MinimizeBox = false;
frmShowPic.MaximizeBox = false;
frmShowPic.ShowIcon = false;
frmShowPic.StartPosition = FormStartPosition.CenterScreen;
frmShowPic.Text = "Show Picture";
/* add panel */
Panel panPic = new Panel();
panPic.AutoSize = false;
panPic.AutoScroll = true;
panPic.Dock = DockStyle.Fill;
/* add picture box */
PictureBox pbPic = new PictureBox();
pbPic.SizeMode = PictureBoxSizeMode.AutoSize;
pbPic.Location = new Point(0, 0);
panPic.Controls.Add(pbPic);
frmShowPic.Controls.Add(panPic);
/* define image */
pbPic.ImageLocation = #"c:\temp\pic.png";
frmShowPic.ShowDialog();
}
The picturebox has to be set to autosize. anchored at the center (or a border).
You could manage all of this in the designer, don't undertand your problem with that.
The panel has to be set to autoscroll to true.

Created image from text cannot be displayed?

I have converted text to Image(.png) using ASP.NET C# in Visual Studio 2010. But the image created cannot be displayed in the browser after submitting and it shows an message
The image "http://localhost:49670/WebSite1/Default.aspx" cannot be displayed, because it contains errors.
During debugging there is no error or warning or anything like that. How can I resolve this?
Looking at the Url there is a chance that you are rendering image intermixed with HTML content...
Using ASHX is better option to render images - check out http://aspalliance.com/1322_Displaying_Images_in_ASPNET_Using_HttpHandlers.all
Try this....
private Bitmap CreateBitmapImage(string sImageText)
{
Bitmap objBmpImage = new Bitmap(1, 1);
int intWidth = 0;
int intHeight = 0;
// Create the Font object for the image text drawing.
Font objFont = new Font("Arial", 20, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
// Create a graphics object to measure the text's width and height.
Graphics objGraphics = Graphics.FromImage(objBmpImage);
// This is where the bitmap size is determined.
intWidth = (int)objGraphics.MeasureString(sImageText, objFont).Width;
intHeight = (int)objGraphics.MeasureString(sImageText, objFont).Height;
// Create the bmpImage again with the correct size for the text and font.
objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight));
// Add the colors to the new bitmap.
objGraphics = Graphics.FromImage(objBmpImage);
// Set Background color
objGraphics.Clear(Color.White);
objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
objGraphics.DrawString(sImageText, objFont, new SolidBrush(Color.FromArgb(102, 102, 102)), 0, 0);
objGraphics.Flush();
return (objBmpImage);
}

Categories

Resources