C++ :: Read All Pixels From Bitmap Into One Big Array
Oct 21, 2013
I need to be able to take a bitmap e.g. "untitled.bmp" (bit depth: 24) and loop through every pixel from top left to bottom right and find the rgb (or hex) value for each pixel e.g. (255,255,255) for white and store this rgb (or hex) value in a two-dimensional array depending on its [column]and[row].
How to read bitmap data in in c++ . Also, I'm reluctant to use windows header files as I'd prefer it to be cross-platform.
How to read pixels from an x,y coordinate using the VGA register values?
byte readVRAMdirect(VGA_Type *VGA, uint_32 start, uint_32 offset) //Used in 256 color mode! { if (!VGA->VRAM_size) return 0; //No size! return VGA->VRAM[SAFEMOD((start*4)+offset,VGA->VRAM_size)]; //The full protected offset!
[code]....
getVRAMScanlineStart(VGA,y) gives the offset register multiplied by 2 (shl 1), multiplied with the current memory address size (byte, word or dword) multiplied by the scanline. 256-color mode is already working. GETBIT gives a bit #(0-7) of a specified byte.
writeVRAMplane & readVRAMplane are used by the CPU to write data to VRAM (address 0xA000:xxxx-0xBFFF:xxxx), determined by the memory read and write modes(working) and the odd/even, planar or chain4 enable mode (working).how to get the 16 color and interleaved shift mode working?
Read *.bmp image and displaying bitmap image with scrollbar in a MFC dialog application.
I was done using this
I was read the *.bmp image as a pixel data and stored by 2D Array,
Now i want to Display this 2D array as bitmap image with scrollbar separately in the same dialog. How can i display bitmap with scrollbar using 2D array?
I am writing a class which loads a bitmap image into a one dimension char* array.
This class has methods to allow for resampling and cropping the image before saving the bitmap image. It works perfectly for all images in which the width is divisible by 4. However when the width is not divisible by 4 the resulting bitmap is all mixed up.
I have spent much of the day googling this problem but to no avail. I know it is a problem with making sure the scanlines are DWORD aligned, and I believe I have done that correctly. I suspect that the problem is that I need to take the padding into account during the crop for loops but am lost to how to do this.
BTW: Coding on Linux using GCC
The following code is a cut down version from my bitmap class. I have removed methods which are not needed to make reading a little easier.
#include "BMP.h" // FIXME (nikki#1#): Portrait bug on images of specific sizes // TODO (nikki#1#): Memory leak checks // THIS METHOD WRITES A BITMAP FILE FROM THE CHAR ARRAY . bool BMP::saveBMP(string fileName, string *err) { FILE *filePtr;
I have a buffer which has a virtual width of 1024 pixels with virtual height 768 pixels (actual width stored in GPU.GPU_screenxsize, height in GPU.GPU_screenysize (both uint_32)).
I currently use the following function to plot the pixels to the screen:
inline void GPU_defaultRenderer() //Default renderer { uint_32 pixel; int bufferx; //Buffer's x! int buffery; //Buffer's y! int bufferxstart; //Buffer's x start! int bufferystart; //Buffer's y start! int pspx;
[Code] ...
How to combine the pixels together (blend them into one goal pixel) to get a better view? (Currently it takes the bottom right pixel of the area that represents the goal pixel).
So (x1,y1,x2,y2)->(pspx,pspy) = (bufferystart,bufferxstart,buffery,bufferx)->(pspx,pspy). Atm this is (x2,y2)->(pspx,pspy)
Btw the pixel format is uint_32 RGBA (only RGB used atm). The psp_graphics_putpixel draws it onto the real VRAM. PSP_SCREEN_ROWS and PSP_SCREEN_COLUMNS represent the destination screen (the real screen)'s height and width in pixels.
I have a project which opens an image in PictureBox1, no problem. But the Public Static Color method at the bottom of the code is not working. I was hoping it would display the average value of the pixels in the image. why it is not working?
Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing.Imaging; using System.Drawing;
getrowsize() gives the size of a row in bytes (see VGA CRTC register). getVRAMMemAddrSize() gives the size of a pixel in memory (1=byte,2=word,4=dword) set/getBitPlaneBit(startaddr,plane,offset,bit[,on when writing]) sets/gets a bit on a specific bit plane offset (start addr is the start address register from VGA, plane is the plane to read/write, offset is the offset within the plane, bit is the bit to read/write (0-7), [on(when writing) is the value of the bit)]
im making a menu system to change the color of pixels in a gravity engine i made. the engine works fine, and the menu colors the particles, but will only ever turn them to red, no matter what color i tell it to change it to.
Instead of using a Bitmap image (jpg, png, etc), I would like to use the desktop. I'm trying to scan my desktop for a pixel color using lockbits (GetPixel was way too slow.). I also do not wish to change the color of anything, I just want to loop until the pixel is found (with my getpixel method, I just put an if/then statement in the for loop). Something like:
I am trying to re-size a bitmap image for a class.They gave us two options to use to do the program with: an array or move the file position indicator. I want to use the file option. All the bitmap header info is checking out. The file after being re-sized should be 822 bytes but it is 1.6 KiB and the image is distorted.
Code:
#include <stdint.h> /** * Common Data Types * * The data types in this section are essentially aliases for C/C++ * primitive data types.
I have a function that essentially takes a screen shot and saves a pointer to it as a structure. I would like to use the same structure for bitmaps that I load from files.
Code: typedef struct _BITMAPCAPTURE { HBITMAP hbm; LPDWORD pixels; INT width; INT height; } BITMAPCAPTURE; BOOL CaptureScreen(BITMAPCAPTURE* bmpCapture) {
[code].....
The handle to the bitmap, as well as the width and height are all easy enough to get but I'm unsure of how to get the pixels.
Writing a program to negate a bitmap image. The program as I have it is asking the user to input a value for the RGB values. But how do I set it up to give the negative of each colour? It has been suggested using the & operator to negate the image inside nested loops.
Also, the RGBQUAD structure was copied into my main program from a BITMAP.H file we were given. However, is it okay just to leave that in the .h file, and just call it from my main program ....if that makes sense?
Anyway, here is my code so far
#include <iostream> #include <fstream> //Used for file I/O #include <cstdlib> //For exit #include <string> #include <algorithm> // for remove_if #include <cctype> // for iswspace
I need to calculate the average brightness of a defined area in a bitmap. Is there a way to select the area which a watermark is going to be applied to, and then find it's average brightness?
I have the below code, but at the moment Color pixel is displaying 0, 0, 0 for RGB, I believe i'm doing it wrong, I have tried to use this as a reference but use part of the image instead of the entire image.
See Company Watermark region!
public void addWatermark() { Image source = Image.FromFile("C:UsersMartyn BallDesktopImages 38.JPG"); Image watermark1 = Image.FromFile(Glb_venueWatermark); Image watermark2 = Image.FromFile(Glb_companyWatermark); //Get width and height of image int sourceWidth = source.Width; int sourceHeight = source.Height;
I've been given the task of converting a java application to a c# windows form application. The program displays a Mandelbrot which then allows the user to zoom into. I've managed to display the Mandelbrot and even zoom. However when dragging a box to zoom, the box its self doesn't show, meaning the user cannot see what area they will be zooming into.
I believe I need to call the update function which draws the rectangle as I drag however no matter what I try, I get errors from a red cross instead of the Mandelbrot to compile errors. Here is the code that I believe is relevant.
public void update(Graphics g) { Color color = Color.White; Pen myPen = new Pen(color); g.DrawImage(myBitmap, 0, 0); if (rectangle) {
I'm trying to create a dialog where some of the buttons have pictures on them, rather than plain text. I notice that under the button's properties, under the "styles" tab there's a checkbox "bitmap". I can't seem to find any easy way of setting a bitmap.
while(1) { CaptureScreenshot (as BMP) Convert screenshot to 24 bit instead of 32 bit Resize screenshot size Get the BMP bits array of the resized screenshot }
I have it working but the best i could get is 18 iteration (screenshots) per second. This is what i do:
Here i do things with piRGB but these things are not counted it the timer so you can assume here the code ends . As said as the code looks now, i can fill piRGB ~18 times (18loops) in 1 second. I must improve that...
I have this code, where I capture window and make copy to bitmap of it. I am working on rotation of bitmap. But my problem is that when I save the image to file the result is just a black screen. It looks like there could be some problem either in GdipCreateBitmapFromHBITMAP() or GdipGetImageGraphicsContext()
How to fix it and to get the rotated image?
Code: // CODE 81 and 82 de facto no difference #defineCODE85 // 81 #defineWINDOW_MIN_HEIGHT200
Now I got rid off the white border but everytime I draw a text it write on top of the previous text so after few seconds everything is a mess and the time is no longer readable.
I have an SDI / CView app (VS 2010). All works well until I minimize the app using the minimize button or drag it partially off of the screen. In the former instance, any attempt to restore the app results in an appcrash with a tight freeze up of the machine. In the later instance the same happens immediately.
In building the app, I scoured the web for code to accomplish the loading and display of the bitmap. After some experimentation I settled on overriding the OnPaint. Below is the code. Note that m_Map is a CBitmap member and IDB_BITMAP1 is a loaded bitmap resource.
Code:
void CMyDragViewView::OnPaint() { // CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CView::OnPaint() for painting messages // http://msgroups.net/microsoft.public.vc.mfc/loading-bitmaps-into-main-window/563285 int x = m_Map.LoadBitmap(IDB_BITMAP1); TRACE1(" x = %d ", x); CPaintDC* dc = new CPaintDC(this);
[code]....
I suspect that the problem is OnPaint trying to repaint the bitmap which requires reloading it, but I don't know how to work around this.
I have a CScrollView that displays a bitmap and I'm trying to draw a grid that I can turn off and on by check box and when the mouse is over a section of the grid that square highlights... I do all the drawing in the ondraw function... But when I have many grid squares it becomes slow to scroll and to highlight the square the mouse is over... I'm not sure the best way to go about this and where to place code to speed it up... The bitmap is only loaded once... But in ondraw the grid has to redraw every time scrolled and when mouse moved over a square.. In onmousemove I call invalidate so the square under mouse changes...
im trying to read in 1 array and get 2 as outputs from 3 different functions.my read array is easy enough were im getting confused is how to read that array, separate it and take out only the parts i want and place them into a 2nd, then again a 3rd array.i have the following so far:
this compiles without a complaint, but when i go to run it no longer responds after taking the 10th element (well 9th if counting from 0).I think i have the if correct for the even odd section, but when i try to populate B or C array with the output of that if statement from A is were i think things are dying...