graphics,png,file-format , How do graphic file format types work?


How do graphic file format types work?

Question:

Tag: graphics,png,file-format

I'm very interested in understanding how graphic file format (PNG, JPG, GIF) work. Are there any code examples that demonstrate how these files are made and also how they are interpreted (viewed in browser)?


Answer:

Regardless of which graphic file format you are working with, you need to understand the basic nature that all graphic files have in common.

Once you understand this basic structure then parsing image files becomes easier once you know the specification to the file structure you are working with. When you know how many bytes to read in to your file pointer that includes all headers and chunks, then you can advance your file pointer to the data structure that will read in or write out all the pixel (color) data. In many cases the pixel data is usually 24bits per pixel such that each channel RGBA - Red, Green, Blue, and Alpha are 8bits each or one byte same as an unsigned char. This is represented in either a structure or a two dimensional array. Either way once you know the file's structure and know how to read in the actual image or color data you can easily store it into a single array. Then what you do with it from there depends on your application's needs.


Related:


Why the first byte of .png file is 0x89?


file,png,formats
I am currently reading about PNG file format. It turns out that the first byte of the file is specified to be equal to 0x89. I am wondering what are the reasons of the value of that byte. What I've already learned about the format is that the first byte...

How do I grep GZ files to extract PNG files?


grep,png,gz
Ok, so I have a tone of .GZ files in a folder, and I'm looking to recursively look through each one of them and extract all the PNG files into another destination folder. How would I do that? EDIT: I've been using this command from the terminal to find a...

picture box crossed out C#


c#,graphics,2d,picturebox,gdi
I have a project in which I draw several rectangles using GDI. I do it using i++ from i=0 to i<=10. I use e.Graphics.FillRectangles. I refresh the drawn rectangles every 1/10s by calling Graphics.Invalidate() My problem is that my picture box gets crossed out when drawing more the 4 rectangles....

Applying rotation to Graphics object


graphics
I have very little experience programming with graphics objects. I am currently tasked with exporting a document (.tiff image) with redacted annotations. The redacted annotation is just a black rectangle object. I am able to get the x coordinates, y coordinates, width and height properties through the .XMP data. There...

PNG transparent backgrounds appearing black when using Android Studio


android,android-studio,png,adt,android-drawable
The social icons below (for fb, twitter, mail and share) are circular PNGs with transparent backgrounds. When I use the code and exact same images in Eclipse, I get transparent background but when build and run with Android Studio, I get black backgrounds. See details below. Images are the same....

How to upscale and render remote(RGB565) frame buffer on Android native?


android,graphics,android-ndk,android-gui,surfaceflinger
I have ported remote frame buffer receive C code on Android 4.2.2 which receives frame buffer from host in RGB565 format. Able to render the received framebuffer following the standard android example frameworks/native/services/surfaceflinger/tests/resize/resize.cpp. Following is the code snippet used sp<Surface> surface = client->createSurface(String8("resize"), 800, 480, PIXEL_FORMAT_RGB_565, 0); SurfaceComposerClient::openGlobalTransaction(); surface->setLayer(100000); SurfaceComposerClient::closeGlobalTransaction();...

How to implement .png pics in a JFrame?


java,graphics,jframe,awt
What I want to do is making a window, a GUI, and putting an image in it. I watched a YT tutorial (https://www.youtube.com/watch?v=Ap20Qw77TzY) and copied everything similar but the Window I make has no image at all. I tried different file types like .jpg and different window sizes, matching he...

What does the terms Sampling,Scanline Mean in Raster Graphics(Bresenham's Algorithm)


algorithm,graphics,raster,vector-graphics
Im a novice when it comes to computer graphics.Im trying to learn Bresenham's Scanline algorithm. It says Pixels positions along a Line are determined by sampling at unit X intervals What exactly does this sampling mean,in layman's terms. Then it says Plot the pixel whose scan line value is closest...

Uploading PNG to Website Server


php,mysql,image,png
I have seen loads of other topics and I've tried them all. Can someone please help with why this script won't upload PNG files? Blank PNG image being displayed. $image = $_FILES['file']['tmp_name']; $image_name = $_FILES['file']['name']; $ext = pathinfo($image_name, PATHINFO_EXTENSION); $location = "Profiles/{$user}/Picture/{$image_name}"; $new_image = imagecreatetruecolor(100, 100); $source_image = imagecreatefrompng($image); imagealphablending($source_image,...

scale in java not working for (-1,1) or (1,-1)


java,graphics
I am trying to make a simple reflection of word "good": So i scale the text good by y axis using g2d.scale(1,-1) but nothing. I am using this simple code: @SuppressWarnings("serial") public class C extends JPanel{ JFrame frame = new JFrame(); public C(){ frame.setSize(500,500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(this); frame.setVisible(true); } public void...

Why does Delphi XE7 change PNG image on every FMX form save?


delphi,png,firemonkey,delphi-xe7
I have a form with many custom firemonkey components where each contain multiple bitmaps (loaded from PNG image files). Every time the form is saved, the binary data of the PNG images change in the FMX file! This messes up my version control log (SVN), as changing just one property...

How colorize Circles in a plot in MATLAB?


matlab,graphics,plot,matlab-figure
I have a MATLAB code as follows: MinVal = -1; MaxVal = 1; MaxRadius = 0.5; nCircles = 5; Dimension = 2; Circles = zeros(nCircles, Dimension); Radius = zeros(nCircles, 1); for i = 1 : nCircles Circles(i,:) = unifrnd(MinVal, MaxVal, [1, Dimension]); Radius(i) = unifrnd(0, MaxRadius, 1); end t =...

Creating new shape palettes in ggplot2 and other R graphics


r,graphics,ggplot2
I'd like to specify my own shape palettes for ggplot2 at least as a vector for input into scale_shape_manual. I really like the paired shapes palette from JMP, but noticed R doesn't have some of these shapes. In particular, sideways triangles (e.g. |> or <|) or a filled upside down...

worklight server preview wont show png resources anymore after configuring it to serve svg


svg,png,worklight
I ran in the problem where svg images were not loading using WorkLight preview. I found the solution for that here: How can I configure Worklight to serve *.svg files with contentType=image/xml+svg? After adding these lines <mimeTypes> <type>svg=image/svg+xml</type> </mimeTypes> svg files appeared on preview, but now i can't load png...

Relationship between AFX_WM_DRAW2D and WM_PAINT in MFC Application


c++,graphics,mfc,directx,direct2d
What is the relationship between the two messages in the subject? When exactly the AFX_WM_DRAW2D is passed to application queue. I am asking because I have encountered the strangest recursive call of AFX_WM_DRAW2D handler. Whenever I am trying to paint something inside the AFX_WM_DRAW2Din compatibe render target the handler is...

Plot: Add legend that overlay several Frames


r,graphics,graph,plot
How can we write a legend that overlay several frames? Using the xpd parameter, the legend can exit its frame but still cannot enter the next frame. par(mfrow=c(1,2)) plot(rnorm(120), rnorm(120)) legend(x = -0.1, y=0.1, legend = "Legend that covers both plots", text.col="red", cex=2, box.col="red", xpd=TRUE) plot(rnorm(120), rnorm(120)) One dummy solution...

Blurring in PyGame


python,graphics,pygame,2d
I'm working on a short intro in PyGame, and I need to blur some static lines. After two days of searching, I can't find anything. Does PyGame have a built-in method to blur a shape or surface? Will I need to do it manually? What would be the best way...

Errors trying to add rectangles to JPanel


java,swing,debugging,graphics
I am trying to draw a grid of rectangles on a JPanel that already has a few JButtons on it. I get a big list of errors when I try to run it. Here's my code: package GameOfLife; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.*;...

Simultaneous Rotate and Translate not working as expected in javafx


graphics,javafx,javafx-8,drag
I have built the following "system" from Circles and a Line. I am trying to implement just following two transitions in the system. When the Green Circle is dragged, both the Green and Blue circle should rotate about the Red center, in the direction of drag. When the Red center...

Why is Java Graphics not painting?


java,graphics
I'm a bit new to programming right now and am trying to make Pong in java. However I'm not able to make any graphics show up. Main Class public class Pong1 { public static Frame frame = new Frame(); public static Panel panel = new Panel(); public static void main(String[]...

Can the OpenGL 'deprecated' functions possibly be unsupported?


c++,c,opengl,graphics,deprecated
I am testing with glDrawPixels to port my simple pixel-drawn 2D game from Windows API to OpenGL with GLFW. It runs nicely with FPS over 100, additionally cross-platform. Just one thing that is slightly annoying me is that I'm using a deprecated feature. I don't see any problems now, but...

Add white rectangle above a screenshot in a Graphics object (java) [duplicate]


java,graphics,draw
This question already has an answer here: How to add text to an image in java? 1 answer I've got a method that's supposed to add some text to screenshots. The screenshot is fed into this method as a File object like this: private void modifyScreenshot(File file) throws Exception...

Plot multiple frames of different size on the same window


r,graphics,graph,plot
Consider this example: par(mfrow=c(2,3)) frame() image(matrix(1:100, nrow=100), main="my wide plot", axes=FALSE) frame() plot(rnorm(120), rnorm(120), main="plot 1") plot(dpois(0:20, lambda=6), type="b", main="plot 2") x = rnorm(100) y = x+runif(100, 10, 12) plot(x=x, y=y, , main="plot 3") How can I do to make my first graph (image(...) titled my wide plot) to occupy...

How to make a Javafx Image Crop App


java,image,canvas,graphics,javafx
I am building an application for my colleagues to crop image. I use FXML with Scene Builder to build the GUI. The user click a button to choose a image from his computer. Then, the image is shown in the GUI. User can zoom and move in the pane. At...

Skip bytes in ByteArray Java


java,png,bytearray,skip
My app reads a png-like file (in byte) and stores bytes into a byteArray. This is the method I use : public static byte[] read(File file) throws IOException { byte []buffer = new byte[(int) file.length()]; InputStream ios = null; try { ios = new FileInputStream(file); if ( ios.read(buffer) == -1...

how to refresh JFrame after after adding java 2d components


java,swing,graphics,graphics2d
in this code i added two components to the jframe and also used revalidate and repaint but only one of the components is being viewed. i need a way to refresh the jframe class A extends JPanel{ int i ,j; A(int i,int j){ this.i = i; this.j = j; }...

How can I convert PNG to GIF keeping the transparency?


delphi,graphics,png,gif
How can I convert PNG to GIF keeping the transparency? I would have hoped that using the Assign( ) method would work but it doesn't seem to migrate transparency. In the GIF, it's represented as black. png:=TPngImage.Create; try png.LoadFromFile(sFile); // comes from file: png.TransparencyMode; // comes from file: png.Transparent //...

Animation not adding to JFrame


java,swing,graphics
I'm new to java swing, so forgive me if my mistake is extremely obvious. What my code is supposed to do here is create one JFrame and animate two boxes moving upwards through the frame side by side. However, I'm seeing only one box (the blue box created by the...

WPF image stop repainting


c#,wpf,mvvm,graphics
Using WPF and MVVM I'm trying to display camera images into a Image. Each frame camera got, a callback is called : Viewmodel public void OnNewFrame(object sender, EventArgs e) { Camera camera = sender as MyCamera; camera.ToBitmap(out _bmpImage); RaisePropertyChanged("BMPImage"); } Each frame, I update the variable _bmpImage : ViewModel private...

AttributeError: '_Screen' object has no attribute 'mainloop'


python,python-2.7,graphics,turtle-graphics
I'm designing a simple Python program that uses the Turtle graphics module to draw lines on the screen with the arrow keys. import turtle turtle.setup(400,500) # Determine the window size wn = turtle.Screen() # Get a reference to the window wn.title("Handling keypresses!") # Change the window title wn.bgcolor("lightgreen") # Set...

C++ Opengl - How to load tgas and pngs in modern OpenGL? [on hold]


image,opengl,c++11,png,tga
I am looking for a way to load tgas and pngs in C++ Opengl - I dislike the idea of using a library though. Is there any sample code / links / advice you could give me in this topic?...

Transform rhombus defined by corners to another rhombus


graphics,transform
If you have a 2D model in the shape of a rhombus, defined by it's four corners, and you want to transform it into the shape of another rhombus, given it's 4 corners, how would you do this? Can you do it with a transformation matrix? My line of thinking...

GDI+ curve “overflowing”


c#,graphics,graph,gdi+
I'm currently using GDI+ to draw a line graph, and using Graphics.DrawCurve to smooth out the line. The problem is that the curve doesn't always match the points I feed it, and that makes the curve grow out of the graph frame in some points, as seen below(red is Graphics.DrawLines,...

Java Unicode character displaying box instead of Runic letter


java,string,unicode,graphics
I am trying to draw random Nordic runes in a little Java game, but all I'm getting back is a square character. public class MyComponent extends JComponent { public void paintComponent(Graphics g) { String s = "\u16A8"; g.drawString(s,50,50); } } What the character should be displaying: https://en.wikipedia.org/wiki/Ansuz_(rune) What it's actually...

Why am I getting a QWidget error?


python,graphics,drawing,pyqt4
I have recently found this person's code that I could possibly be able to use for my project but I'm still pretty new to Python so I'm having a really rough time understanding the code and the error that keeps occurring even though the code is exactly the same as...

Swift - UIGraphics dash line close


swift,graphics,line,dash
This is my code: UIGraphicsBeginImageContextWithOptions(CGSizeMake(self.view.frame.width,graphSize), false, 0) let context = UIGraphicsGetCurrentContext() CGContextSetStrokeColorWithColor(context, UIColor.whiteColor().CGColor) CGContextSetLineWidth(context, 0.3) CGContextBeginPath(context) CGContextMoveToPoint(context, width1, height1) CGContextAddLineToPoint(context, width11, height11) CGContextMoveToPoint(context, width2, height2) CGContextAddLineToPoint(context, width22, height22) //dash line CGContextStrokePath(context)...

Rename a bunch of PNG images with “.jpg” extension to “.png”


image,bash,scripting,png,jpeg
So I have a folder with thousands of image files, all of them saved as .jpg. The problem is that some of those files are actually PNG image files, so they don't open in a lot of programs, unless I manually change their extension to .png. For example, the Ubuntu...

Reflecting text in java


java,graphics
I am trying to make a digital clock in this way: As shown in the image 1 i want the clock to be reflected. image 1 made in blender What i have tried: I tried using java (Graphics2D)g by rotating the string and the using substring but i got this...

Moving a graphics 2d object with threads


java,multithreading,swing,graphics
I am not quite sure why my boat is not moving. If anyone could explain in detail that would be great. This is what creates and shows the boat: import java.awt.Color; import java.awt.Graphics; import javax.swing.JApplet; @SuppressWarnings("serial") public class boatApplet extends JApplet{ public void paint(Graphics g) { setBackground(Color.blue); // Xposition, YPosition,...

Getting the font metrics before the paint method id called


java,animation,graphics,fontmetrics
Hi I am creating a news ticker/ text scroller. I am using the following method: import java.awt.Color; import java.awt.FontMetrics; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class Scroll1 extends JPanel{ private int x; private int x2; private int y; private String text; final int startX=-100; public Scroll1(int startX) { x2=-650;...

C++ GUI Challenge


c++,graphics,programming-languages,monogame
Recently I was challenged by a friend to create a snake game much like the classic Nokia version using the C++ language. I have been programming in Java, but unlike Java, C++ doesn't seem to have standard gui libraries. Therefore after looking into GUI for C++ many different api are...

Spotlight with shadows becomes square-like


c++,opengl,graphics,shader,shadow
I've been following a two part tutorial on shadow mapping from OGLDev (part 1, part 2) for a couple of days now, and I've nearly finished implementing it. My problem is that when I enable shadow maps the illuminated region which shadows appear in appears as a "strip" and I'm...

Why is my rectangle being drawn wrong?


ios,swift,graphics,sprite-kit
I'm trying to draw a rectangle around my screen. Here's my code: let viewRect = SKShapeNode(rect: self.view!.frame) viewRect.strokeColor = SKColor.whiteColor() viewRect.lineWidth = 2.0 addChild(viewRect) I'm using self.view!.frame instead of self.frame because my scene is not the same size as my screen (the scene is stretched to fill my screen). I...

Buttons and paint method


java,swing,graphics,jbutton,actionlistener
I'm having trouble with my buttons. I know they're working because I've tested them out by exiting the problem through System.exit. Here is what my output looks like: http://imgur.com/Ks7mIFa When I click the close button, the handle on the switch should redraw to the other side and the close button...

How to create an indent in shaped control that allows painting on indented region?


c#,graphics,shape
I have a custom control, which I am applying a shape to. The shape has a pointer (similar to the message indicator in Skype that shows if the message was a received message, or a sent message) that is on the left or right side. When the indicator is on...

C++ Bitmap Resource (RT_BITMAP) and PNG Image Format


c++,bitmap,png
An application I'm developing displays various PNG images to the user in a window, and it works fine. My question is more on the grounds on HOW my PNG's are stored in the PE. Currently, the PNG's are stored in the executable as a resource, under the RT_RCDATA Resource Type,...

Transparent RichTextBox with Graphic not showing Text


c#,winforms,graphics,transparency,richtextbox
I have the following code working, and commented out the Text being drawn onto the control as I started out using this as a graphic only control. Moving on, I have switched the control to be RichTextBox instead of Control so that I can have all the goodies that come...

Extracting vector graphics (lines and points) with pdfclown


vector,graphics,pdfclown
I want to extract vector graphics (lines and points) out of a pdf with pdfclown. I have tried to wrap my head around the graphics sample but i cannot figure out how the object model works for this. Please can anyone explain the relationships?

Interactive bend image


css3,graphics,html5-canvas
I'd like to transform image in web browser this way -> more precisely, it should be 3D effect (like wrap the image around can). I'm considering these options: CSS3 transform (is it possible with matrix3d somehow?) HTML5 canvas (I don't have any experience here yet) applet or flash (this would...