Search Results

Search found 510 results on 21 pages for 'bmp'.

Page 8/21 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • How can I overwrite a System.Drawing.Bitmap onto an existing GDI bitmap?

    - by MusiGenesis
    If I have a .Net Bitmap, I can create from it a GDI bitmap by calling the Bitmap's GetHbitmap() method. Bitmap bmp = new Bitmap(100, 100); IntPtr gdiBmp = bmp.GetHbitmap(); This works fine, but every time you call GetHbitmap, Windows has to allocate new memory for the object that gdiBmp references. What I'd like to do - if possible - is write a function (I know PInvoke will be necessary here) that also generates a GDI bitmap copy of a Bitmap, but that uses an existing object instead of allocating a new one. So it would look something like this (if it were an extension method of Bitmap): //void OverwriteHbitmap(IntPtr gdi) Bitmap bmp1 = new Bitmap(100, 100); IntPtr gdi1 = bmp1.GetHbitmap(); Bitmap bmp2 = new Bitmap(100, 100); bmp2.OverwriteHbitmap(gdi1); How can I do this? I assume I'll need to know the structure of a GDI bitmap, and probably I can use LockBits and BitmapData for this, but I'm not sure exactly how.

    Read the article

  • Why does this thumbnail generation code throw OutOfMemoryException on large files?

    - by tsilb
    This code works great for generating thumbnails, but when given a very large (100MB+) TIFF file, it throws OutOfMemoryExceptions. When I do it manually in Paint.NET on the same machine, it works fine. How can I improve this code to stop throwing on very large files? In this case I'm loading a 721MB TIF on a machine with 8GB RAM. The Task Manager shows 2GB used so something is preventing it from using all that memory. Specifically it throws when I load the Image to calculate the size of the original. What gives? /// <summary>Creates a thumbnail of a given image.</summary> /// <param name="inFile">Fully qualified path to file to create a thumbnail of</param> /// <param name="outFile">Fully qualified path to created thumbnail</param> /// <param name="x">Width of thumbnail</param> /// <returns>flag; result = is success</returns> public static bool CreateThumbnail(string inFile, string outFile, int x) { // Validation - assume 16x16 icon is smallest useful size. Smaller than that is just not going to do us any good anyway. I consider that an "Exceptional" case. if (string.IsNullOrEmpty(inFile)) throw new ArgumentNullException("inFile"); if (string.IsNullOrEmpty(outFile)) throw new ArgumentNullException("outFile"); if (x < 16) throw new ArgumentOutOfRangeException("x"); if (!File.Exists(inFile)) throw new ArgumentOutOfRangeException("inFile", "File does not exist: " + inFile); // Mathematically determine Y dimension int y; using (Image img = Image.FromFile(inFile)) { // OutOfMemoryException double xyRatio = (double)x / (double)img.Width; y = (int)((double)img.Height * xyRatio); } // All this crap could have easily been Image.Save(filename, x, y)... but nooooo.... using (Bitmap bmp = new Bitmap(inFile)) using (Bitmap thumb = new Bitmap((Image)bmp, new Size(x, y))) using (Graphics g = Graphics.FromImage(thumb)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; System.Drawing.Imaging.ImageCodecInfo codec = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[1]; System.Drawing.Imaging.EncoderParameters ep2 = new System.Drawing.Imaging.EncoderParameters(1); ep2.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); g.DrawImage(bmp, new Rectangle(0,0,thumb.Width, thumb.Height)); try { thumb.Save(outFile, codec, ep2); return true; } catch { return false; } } }

    Read the article

  • How to convert a AChartEngine chart to bitmap

    - by user2137817
    I want to convert a line graph I made with AChartEngine lib to bitmap.How should I do?I didn't found on the net anything that can help. Is the toBitmap() method suitable?if yes then how to use it? Update: I used this method : public static Bitmap loadBitmapFromView(View v) { v.setDrawingCacheEnabled(true); v.layout( 0,0,800,600); v.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); v.buildDrawingCache(); v.getDrawingCache(); Bitmap bmp = Bitmap.createBitmap(800,600, Bitmap.Config.ARGB_8888); v.setDrawingCacheEnabled(false); return bmp; } and saved the result in a png file but all I got is an empty file !

    Read the article

  • Sort and display directory list alphabetically using opendir() in php

    - by felixthehat
    Hi there, php noob here - I've cobbled together this script to display a list of images from a folder with opendir, but I can't work out how (or where) to sort the array alphabetically <?php // opens images folder if ($handle = opendir('Images')) { while (false !== ($file = readdir($handle))) { // strips files extensions $crap = array(".jpg", ".jpeg", ".JPG", ".JPEG", ".png", ".PNG", ".gif", ".GIF", ".bmp", ".BMP", "_", "-"); $newstring = str_replace($crap, " ", $file ); //asort($file, SORT_NUMERIC); - doesnt work :( // hides folders, writes out ul of images and thumbnails from two folders if ($file != "." && $file != ".." && $file != "index.php" && $file != "Thumbnails") { echo "<li><a href=\"Images/$file\" class=\"thickbox\" rel=\"gallery\" title=\"$newstring\"><img src=\"Images/Thumbnails/$file\" alt=\"$newstring\" width=\"300\" </a></li>\n";} } closedir($handle); } ?> Any advice or pointers would be much appreciated!

    Read the article

  • Trying to capture stage area using BitmapData

    - by Dimitree
    I am trying to grab part of stage area using BitmapData and copyPixels method: bmd = new BitmapData(stage.stageWidth, stage.stageHeight); bmdRect = new BitmapData(320, 240); rectangle = new Rectangle(360, 20, 320, 240); bmdRect.copyPixels(bmd, rectangle, new Point()); bmd.draw(bmp); bmp = new Bitmap(bmdRect); var myEncoder:JPGEncoder = new JPGEncoder(100); var byteArray:ByteArray = myEncoder.encode(bmd); The result i get is an empty .jpg I m pretty sure that the error is in the Bitmap procedure and not the saving one...

    Read the article

  • How do I remove (or apply) transparency on a gdk-pixbuf?

    - by Andrew Stacey
    I have a c++ program in which a gdk-pixbuf is created. I want to output it as an image, so I call gdk_pixbuf_save_to_stream(pixbuf,stream,type,NULL,&err,NULL). This works fine when "type" is png or tiff, but with jpeg or bmp it just produces a black square. The original pixbuf consists of black-on-transparent (and gdk_pixbuf_get_has_alpha returns true) so I'm guessing that the problem is with the alpha mask. GdkPixbuf has a function to add an alpha channel, but I can't see one that removes it again, or (which might be as good) to invert it. Is there a simple way to get the jpeg and bmp formats to work properly? (I should say that I'm very new to proper programming like this.)

    Read the article

  • How does Bitmap.Save(Stream, ImageFormat) format the data?

    - by Matt Jacobsen
    I have a non transparent, colour bitmap with length 2480 and width 3507. Using Bitmap.GetPixel(int x, int y) I am able to get the colour information of each pixel in the bitmap. If I squirt the bitmap into a byte[]: MemoryStream ms = new MemoryStream(); bmp.Save(ms, ImageFormat.Bmp); ms.Position = 0; byte[] bytes = ms.ToArray(); then I'd expect to have the same information, i.e. I can go to bytes[1000] and read the colour information for that pixel. It turns out that my array of bytes is larger than I anticipated. I thought I'd get an array with 2480 x 3507 = 8697360 elements. Instead I get an array with 8698438 elements - some sort of header I presume. In what format the bytes in my array stored? Is there a header 1078 bytes long followed by Alpha, Red, Green, Blue values for every byte element, or something else?

    Read the article

  • WPF Dispatcher {"The calling thread cannot access this object because a different thread owns it."}

    - by user359446
    first I need to say that I´m noob with WPF and C#. Application: Create Mandelbrot Image (GUI) My disptacher works perfektly this this case: private void progressBarRefresh(){ while ((con.Progress) < 99) { progressBar1.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate { progressBar1.Value = con.Progress; } )); } } I get the Message (Title) when tring to do this with the below code: bmp = BitmapSource.Create(width, height, 96, 96, pf, null, rawImage, stride); this.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate { img.Source = bmp; ViewBox.Child = img; //vllt am schluss } )); I will try to explain how my program works. I created a new Thread (because GUI dont response) for the calculation of the pixels and the colors. In this Thread(Mehtod) I´m using the Dispatcher to Refresh my Image in the ViewBox after the calculations are ready. When I´m dont put the calculation in a seperate Thread then I can refresh or build my Image.

    Read the article

  • ImageChops.duplicate - python

    - by ariel
    Hi I am tring to use the function ImageChops.dulpicate from the PIL module and I get an error I don't understand: this is the code import PIL import Image import ImageChops import os PathDemo4a='C:/Documents and Settings/Ariel/My Documents/My Dropbox/lecture/demo4a' PathDemo4b='C:/Documents and Settings/Ariel/My Documents/My Dropbox/lecture/demo4b' PathDemo4c='C:/Documents and Settings/Ariel/My Documents/My Dropbox/lecture/demo4c' PathBlackBoard='C:/Documents and Settings/Ariel/My Documents/My Dropbox/lecture/BlackBoard.bmp' Slides=os.listdir(PathDemo4a) for slide in Slides: #BB=Image.open(PathBlackBoard) BB=ImageChops.duplicate(PathBlackBoard) #BB=BlackBoard and this is the error; Traceback (most recent call last): File "", line 1, in ImageChops.duplicate('c:/1.BMP') File "C:\Python26\lib\site-packages\PIL\ImageChops.py", line 57, in duplicate return image.copy() AttributeError: 'str' object has no attribute 'copy' any help would be much appriciated Ariel

    Read the article

  • Python Imaging: YCbCr problems

    - by daver
    Hi, I'm doing some image processing in Python using PIL, I need to extract the luminance layer from a series of images, and do some processing on that using numpy, then put the edited luminance layer back into the image and save it. The problem is, I can't seem to get any meaningful representation of my Image in a YCbCr format, or at least I don't understand what PIL is giving me in YCbCr. PIL documentation claims YCbCr format gives three channels, but when I grab the data out of the image using np.asarray, I get 4 channels. Ok, so I figure one must be alpha. Here is some code I'm using to test this process: import Image as im import numpy as np pengIm = im.open("Data\\Test\\Penguins.bmp") yIm = pengIm.convert("YCbCr") testIm = np.asarray(yIm) grey = testIm[:,:,0] grey = grey.astype('uint8') greyIm = im.fromarray(grey, "L") greyIm.save("Data\\Test\\grey.bmp") I'm expecting a greyscale version of my image, but what I get is this jumbled up mess: http://i.imgur.com/zlhIh.png Can anybody explain to me where I'm going wrong? The same code in matlab works exactly as I expect.

    Read the article

  • How to invoke a delegate with a null parameter?

    - by Rodney Burton
    I get a null exception if I try to pass a null parameter to a delegate during an invoke. Here's what the code looks like: public void RequestPhoto() { WCF.Service.BeginGetUserPhoto(Contact.UserID, new AsyncCallback(RequestPhotoCB), null); } public void RequestPhotoCB(IAsyncResult result) { var photo = WCF.Service.EndGetUserPhoto(result); UpdatePhoto(photo); } public delegate void UpdatePhotoDelegate(Binary photo); public void UpdatePhoto(Binary photo) { if (InvokeRequired) { var d = new UpdatePhotoDelegate(UpdatePhoto); Invoke(d, new object[] { photo }); } else { var ms = new MemoryStream(photo.ToArray()); var bmp = new Bitmap(ms); pbPhoto.BackgroundImage = bmp; } } The problem is with the line: Invoke(d, new object[] { photo }); If the variable "photo" is null. What is the correct way to pass a null parameter during an invoke? Thanks!

    Read the article

  • How to set up a Bitmap with unmanaged data?

    - by Danvil
    I have int width, height; and IntPtr data; which comes from a unmanaged unsigned char* pointer and I would like to create a Bitmap to show the image data in a GUI. Please consider, that width must not be a multiple of 4, i do not have a "stride" and my image data is aligned as BGRA. The following code works: byte[] pixels = new byte[4*width*height]; System.Runtime.InteropServices.Marshal.Copy(data, pixels, 0, pixels.Length); var bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for(int i=0; i<height; i++) { for(int j=0; j<width; j++) { int p = 4*(width*i + j); bmp.SetPixel(j, i, Color.FromArgb(pixels[p+3], pixels[p+2], pixels[p+1], pixels[p+0])); } } Is there a more direct way to copy the data?

    Read the article

  • How to Add Icon to a Excel Menu/Toolbar Button

    - by nimo
    Hi, I need to add a image to a custom toolbar/menu item which is create through VBA. For a toolbar item, I tried following code Set NewBtn = TBar.Controls.Add(Type:=msoControlButton) With NewBtn .Picture = LoadPicture("mypic.bmp") .OnAction = "'MyFunction""" & para1 & """'" //VBA Function '.Caption = "MyFunction" .TooltipText = "MyFunction" .Style = msoButtonCaption End With In the above code LoadPicture() does not seem to be working. My toolbar is initializing at the workbook load up event. I noticed that the image is loading to the toolbar button, but in a fraction of second it disappears and only item text is displayed. My image is 16x16 pixel bmp one. Any help appreciate to get around this problem Thank you

    Read the article

  • Controlling the visibility of a Bitmap in .NET

    - by ET
    Hi everyone, I am trying to create this simple application in c#: when the user double clicks on specific location in the form, a little circle will be drawn. By one click, if the current location is marked by a circle - the circle will be removed. I am trying to do this by simply register the MouseDoubleClick and MouseClick events, and to draw the circle from a .bmp file the following way: private void MouseDoubleClick (object sender, MouseEventArgs e) { Graphics g = this.CreateGraphics(); Bitmap myImage = (Bitmap)Bitmap.FromFile("Circle.bmp"); g.DrawImage(myImage, e.X, e.Y); } My problem is that I dont know how to make the circle unvisible when the user clicks its location: I know how to check if the selected location contains a circle (by managing a list of all the locations containig circles...), but I dont know how exactly to delete it. Another question: should I call the method this.CreateGraphics() everytime the user double-clicks a location, as I wrote in my code snippet, or should I call it once on initialization?

    Read the article

  • Creating a Dib by only specifying the size with GDI+ and DotNet...

    - by Kris Erickson
    I have just recently discovered the difference between different constructors in GDI+. Going: var bmp = new Bitmap(width, height, pixelFormat); creates a DDB (Device Dependent Bitmap) whereas: var bmp = new Bitmap(someFile); creates a DIB (Device Independent Bitmap). This is really not usually important, except when handling very large images (where a DDB will run out of memory, and run out of memory at different sizes depending on the machine and its video memory). I need to create a DIB rather than DDB, but specify the height, width and pixelformat. Does anyone know how to do this in DotNet. Also is there a guide to what type of Bitmap (DIB or DDB) is being created by which Bitmap constructor?

    Read the article

  • Controling the visibility of a Bitmap in .NET

    - by ET
    Hi everyone, I am trying to create this simple application in c#: when the user double clicks on specific location in the form, a little circle will be drawn. By one click, if the current location is marked by a circle - the circle will be removed. I am trying to do this by simply register the MouseDoubleClick and MouseClick events, and to draw the circle from a .bmp file the following way: private void MouseDoubleClick (object sender, MouseEventArgs e) { Graphics g = this.CreateGraphics(); Bitmap myImage = (Bitmap)Bitmap.FromFile("Circle.bmp"); g.DrawImage(myImage, e.X, e.Y); } My problem is that I dont know how to make the circle unvisible when the user clicks its location: I know how to check if the selected location contains a circle (by managing a list of all the locations containig circles...), but I dont know how exactly to delete it. Another question: should I call the method this.CreateGraphics() everytime the user double-clicks a location, as I wrote in my code snippet, or should I call it once on initialization?

    Read the article

  • Optimizing GDI+ drawing?

    - by user146780
    I'm using C++ and GDI+ I'm going to be making a vector drawing application and want to use GDI+ for the drawing. I'v created a simple test to get familiar with it: case WM_PAINT: GetCursorPos(&mouse); GetClientRect(hWnd,&rct); hdc = BeginPaint(hWnd, &ps); MemDC = CreateCompatibleDC(hdc); bmp = CreateCompatibleBitmap(hdc, 600, 600); SelectObject(MemDC,bmp); g = new Graphics(MemDC); for(int i = 0; i < 1; ++i) { SolidBrush sb(Color(255,255,255)); g->FillRectangle(&sb,rct.top,rct.left,rct.right,rct.bottom); } for(int i = 0; i < 250; ++i) { pts[0].X = 0; pts[0].Y = 0; pts[1].X = 10 + mouse.x * i; pts[1].Y = 0 + mouse.y * i; pts[2].X = 10 * i + mouse.x; pts[2].Y = 10 + mouse.y * i; pts[3].X = 0 + mouse.x; pts[3].Y = (rand() % 600) + mouse.y; Point p1, p2; p1.X = 0; p1.Y = 0; p2.X = 300; p2.Y = 300; g->FillPolygon(&b,pts,4); } BitBlt(hdc,0,0,900,900,MemDC,0,0,SRCCOPY); EndPaint(hWnd, &ps); DeleteObject(bmp); g->ReleaseHDC(MemDC); DeleteDC(MemDC); delete g; break; I'm wondering if I'm doing it right, or if I have areas killing the cpu. Because right now it takes ~ 1sec to render this and I want to be able to have it redraw itself very quickly. Thanks In a real situation would it be better just to figure out the portion of the screen to redraw and only redraw the elements withing bounds of this?

    Read the article

  • C# GDI - How to check if a Pixel is opaque or not?

    - by rkawano
    I am using a method to get a pixel of the image to check if this point is transparent or not. I am using GetPixel that returns a System.Drawing.Color with a 32bit color info. This struct have the "A" property where I can get the alpha value of pixel, according to this MSDN topic. Code: using (Bitmap bmp = new Bitmap(path)) { Color pixel = bmp.GetPixel(0, 0); if (pixel.A == 0) // This is a fully transparent pixel else // This is not a fully transparent pixel } When I use this method with a fully transparent PNG images it returns 0. When I run with a white semi-transparent images, it will give me other values starting on 1 and up to 86, where 86 are given for images with a 100% alfa (full opaque). But with opaque JPEG images, the "A" property are giving me all sort of values like 56, 71, 86, 129, and others, depending on image. But these pixels are fully opaques! How are the correct way to check if a pixel is opaque or not?

    Read the article

  • Why does this code crash?

    - by user146780
    The following code causes a stack overflow but I don't see why... int _tmain(int argc, _TCHAR* argv[]) { cout << "start"; char bmp[1024][768][3]; for (int p = 0; p < 9000; ++p) { for(int i = 0; i < 1024; ++i) { for(int j = 0; j < 768; ++j) { bmp[i][j][0] = 20; } } } cout << "Stop"; return 0; } Thanks

    Read the article

  • C# Dispatcher {"The calling thread cannot access this object because a different thread owns it."}

    - by user359446
    Hi, first I need to say that I´m noob with WPF and C#. Application: Create Mandelbrot Image (GUI) My disptacher works perfektly this this case: private void progressBarRefresh(){ while ((con.Progress) < 99) { progressBar1.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate { progressBar1.Value = con.Progress; } )); } } I get the Message (Title) when tring to do this with the below code: bmp = BitmapSource.Create(width, height, 96, 96, pf, null, rawImage, stride); this.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate { img.Source = bmp; ViewBox.Child = img; //vllt am schluss } )); I will try to explain how my program works. I created a new Thread (because GUI dont response) for the calculation of the pixels and the colors. In this Thread(Mehtod) I´m using the Dispatcher to Refresh my Image in the ViewBox after the calculations are ready. When I´m dont put the calculation in a seperate Thread then I can refresh or build my Image. PS: Sry for my bad english

    Read the article

  • C#: Using regular expression (Regex) to duplicate a specific character in a string

    - by user3703944
    Anyone know how to use regex to duplicate a specific character in a string? I have a path that is entered like this: C:/Example/example I would like to use regex (or any other method) to display it like this: C://Example//example Is it possible? This is where I'm getting the file path private void btnSearchImage_Click_1(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string filenName = ofd.FileName; pictureBox1.Image = new Bitmap(filenName); string path = filenName; txtimgPath.Text = path; } } Thanks

    Read the article

  • Print SSRS Report / PDF automatically from SQL Server agent or Windows Service

    - by Jeremy Ramos
    Originally posted on: http://geekswithblogs.net/JeremyRamos/archive/2013/10/22/print-ssrs-report--pdf-from-sql-server-agent-or.aspxI have turned the Web upside-down to find a solution to this considering the least components and least maintenance as possible to achieve automated printing of an SSRS report. This is for the reason that we do not have a full software development team to maintain an app and we have to minimize the support overhead for the support team.Here is my setup:SQL Server 2008 R2 in Windows Server 2008 R2PDF format reports generated by SSRS Reports subscriptions to a Windows File ShareNetwork printerColoured reports with logo and brandingI have found and tested the following solutions to no avail:ProsConsCalling Adobe Acrobat Reader exe: "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\acroRd32.exe" /n /s /o /h /t "C:\temp\print.pdf" \\printserver\printername"Very simple optionAdobe Acrobat reader requires to launch the GUI to send a job to a printer. Hence, this option cannot be used when printing from a service.Calling Adobe Acrobat Reader exe as a process from a .NET console appA bit harder than above, but still a simple solutionSame as cons abovePowershell script(Start-Process -FilePath "C:\temp\print.pdf" -Verb Print)Very simple optionUses default PDF client in quiet mode to Print, but also requires an active session.    Foxit ReaderVery simple optionRequires GUI same as Adobe Acrobat Reader Using the Reporting Services Web service to run and stream the report to an image object and then passed to the printerQuite complexThis is what we're trying to avoid  After pulling my hair out for two days, testing and evaluating the above solutions, I ended up learning more about printers (more than ever in my entire life) and how printer drivers work with PostScripts. I then bumped on to a PostScript interpreter called GhostScript (http://www.ghostscript.com/) and then the solution starts to get clearer and clearer.I managed to achieve a solution (maybe not be the simplest but efficient enough to achieve the least-maintenance-least-components goal) in 3-simple steps:Install GhostScript (http://www.ghostscript.com/download/) - this is an open-source PostScript and PDF interpreter. Printing directly using GhostScript only produces grayscale prints using the laserjet generic driver unless you save as BMP image and then interpret the colours using the imageInstall GSView (http://pages.cs.wisc.edu/~ghost/gsview/)- this is a GhostScript add-on to make it easier to directly print to a Windows printer. GSPrint automates the above  PDF -> BMP -> Printer Driver.Run the GSPrint command from SQL Server agent or Windows Service:"C:\Program Files\Ghostgum\gsview\gsprint.exe" -color -landscape -all -printer "printername" "C:\temp\print.pdf"Command line options are here: http://pages.cs.wisc.edu/~ghost/gsview/gsprint.htmAnother lesson learned is, since you are calling the script from the Service Account, it will not necessarily have the Printer mapped in its Windows profile (if it even has one). The workaround to this is by adding a local printer as you normally would and then map this printer to the network printer. Note that you may need to install the Printer Driver locally in the server.So, that's it! There are many ways to achieve a solution. The key thing is how you provide the smartest solution!

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >